UNPKG

class-validator-extended

Version:
27 lines (26 loc) 1.26 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.maxDayjs = maxDayjs; const dayjs_1 = __importDefault(require("dayjs")); const is_dayjs_1 = require("../../type/is-dayjs"); /** * @category Predicates * @param value The value to validate. * @param maximum The maximum allowed value. * @param options Additional options (see {@link MaxDayjs}). */ function maxDayjs(value, maximum, options) { var _a, _b; const max = (0, dayjs_1.default)(maximum); 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 (!max.isValid()) { throw new TypeError(`Parameter "maximum" 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) && (max.isAfter(value, granularity) || (inclusive && max.isSame(value, granularity)))); }