UNPKG

class-validator-extended

Version:
27 lines (26 loc) 1.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.minDayjs = minDayjs; const dayjs_1 = __importDefault(require("dayjs")); const is_dayjs_1 = require("../../type/is-dayjs"); /** * @category Predicates * @param value The value to validate. * @param minimum The minimum allowed value. * @param options Additional options (see {@link MinDayjs}). */ function minDayjs(value, minimum, options) { var _a, _b; const min = (0, dayjs_1.default)(minimum); const inclusive = (_a = options === null || options === void 0 ? void 0 : options.inclusive) !== null && _a !== void 0 ? _a : false; const granularity = (_b = options === null || options === void 0 ? void 0 : options.granularity) !== null && _b !== void 0 ? _b : 'milliseconds'; if (!min.isValid()) { throw new TypeError(`Parameter "minimum" must be a valid date`); } // Let's not rely on the isSameOrBefore-plugin which might or might not be registered. return ((0, is_dayjs_1.isDayjs)(value, options) && (min.isBefore(value, granularity) || (inclusive && min.isSame(value, granularity)))); }