class-validator-extended
Version:
Additional validators for class-validator.
31 lines (30 loc) • 1.16 kB
TypeScript
import type { ValidationOptions } from 'class-validator';
import type { Duration, DurationUnitsObjectType, DurationUnitType } from 'dayjs/plugin/duration';
/** @hidden */
export declare const MIN_DURATION = "minDuration";
/**
* Checks if the given value is a valid Dayjs duration not longer than `minimum`.
*
* The minimum can be given as either:
* - a Dayjs duration
* - an ISO 8601 string, e.g. `"PT1H"`
* - a units object, e.g. `{ hour: 1, minute: 30 }`
* - a time/unit tuple, e.g. `[1, 'hour]`
*
* #### Example
* ```typescript
* // Ensure the value is a duration at least 1 hour long
* @MinDuration([1, 'hour'], { inclusive: true })
* value: Duration
* ```
*
* @category Dayjs
* @param minimum The minimum allowed value.
* @param options
* Accepts the following options (in addition to generic class-validator options):
* - `inclusive: boolean = false`
* If true, allow the `minimum` duration as well.
*/
export declare function MinDuration(minimum: Duration | string | DurationUnitsObjectType | [time: number, unit?: DurationUnitType], options?: {
inclusive?: boolean;
} & ValidationOptions): PropertyDecorator;