UNPKG

class-validator-extended

Version:
33 lines (32 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PAST_DATE = void 0; exports.PastDate = PastDate; const class_validator_1 = require("class-validator"); const past_date_predicate_1 = require("./past-date.predicate"); /** @hidden */ exports.PAST_DATE = 'pastDate'; /** * Checks if the given value is a Date object in the past. * * Beware that the behaviour of this check depends on the current time and can thus be difficult to test. * * #### Example * ```typescript * // Ensure the value is in the past. * @PastDate() * created: Date * ``` * * @category Date * @param options Generic class-validator options. */ function PastDate(options) { return (0, class_validator_1.ValidateBy)({ name: exports.PAST_DATE, validator: { validate: (value, _arguments) => (0, past_date_predicate_1.pastDate)(value), defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must be a Date instance in the past`, options), }, }, options); }