UNPKG

class-validator-extended

Version:
25 lines (24 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.maxDuration = maxDuration; const is_duration_1 = require("../../type/is-duration"); const create_duration_1 = require("../create-duration"); const is_valid_duration_1 = require("../is-valid-duration"); /** * @category Predicates * @param value The value to validate. * @param maximum The maximum allowed duration. * @param options Additional options (see {@link MaxDuration}). */ function maxDuration(value, maximum, options) { var _a; const max = (0, create_duration_1.createDuration)(maximum); if (!(0, is_valid_duration_1.isValidDuration)(max)) { throw new TypeError('Parameter "maximum" must be a valid Dayjs duration'); } const inclusive = (_a = options === null || options === void 0 ? void 0 : options.inclusive) !== null && _a !== void 0 ? _a : false; return ((0, is_duration_1.isDuration)(value) && (inclusive ? value.asMilliseconds() <= max.asMilliseconds() : value.asMilliseconds() < max.asMilliseconds())); }