UNPKG

class-validator-extended

Version:
31 lines (30 loc) 1.16 kB
import type { ValidationOptions } from 'class-validator'; import type { Duration, DurationUnitsObjectType, DurationUnitType } from 'dayjs/plugin/duration'; /** @hidden */ export declare const MAX_DURATION = "maxDuration"; /** * Checks if the given value is a valid Dayjs duration not longer than `maximum`. * * 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 most 1 hour long * @MaxDuration([1, 'hour'], { inclusive: true }) * value: Duration * ``` * * @category Dayjs * @param maximum The maximum allowed value. * @param options * Accepts the following options (in addition to generic class-validator options): * - `inclusive: boolean = false` * If true, allow the `maximum` duration as well. */ export declare function MaxDuration(maximum: Duration | string | DurationUnitsObjectType | [time: number, unit?: DurationUnitType], options?: { inclusive?: boolean; } & ValidationOptions): PropertyDecorator;