class-validator
class-validator copied to clipboard
feature: add `IsDurationString` to validate duration strings
Description
I would like to have an IsDurationString decorator that validates duration strings ("1 Day", "2 weeks", "7 hrs"...) from the ms package, exactly the ms.StringValue type.
An IsDuration decorator could be considered too, which validates for either a positive integer (milliseconds) or a duration string. (basically, the value is valid to pass to the ms function).
Proposed solution
Implementation of the validator could be either:
- Having
mslibrary as a dependency: try converting the value throughms, if it succeeds then the value is valid. - Implementing an
ms-like parser for validation, without adding a dependency.
In case this feature is considered, I'd be glad to open a PR & know which approach aligns more with the project (since one of them needs additional dependency).