UNPKG

1.57 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.IsISO8601 = exports.isISO8601 = exports.IS_ISO8601 = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isISO8601_1 = __importDefault(require("validator/lib/isISO8601"));
9exports.IS_ISO8601 = 'isIso8601';
10/**
11 * Checks if the string is a valid ISO 8601 date.
12 * If given value is not a string, then it returns false.
13 * Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29.
14 */
15function isISO8601(value, options) {
16 return typeof value === 'string' && (0, isISO8601_1.default)(value, options);
17}
18exports.isISO8601 = isISO8601;
19/**
20 * Checks if the string is a valid ISO 8601 date.
21 * If given value is not a string, then it returns false.
22 * Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29.
23 */
24function IsISO8601(options, validationOptions) {
25 return (0, ValidateBy_1.ValidateBy)({
26 name: exports.IS_ISO8601,
27 constraints: [options],
28 validator: {
29 validate: (value, args) => isISO8601(value, args.constraints[0]),
30 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a valid ISO 8601 date string', validationOptions),
31 },
32 }, validationOptions);
33}
34exports.IsISO8601 = IsISO8601;
35//# sourceMappingURL=IsISO8601.js.map
\No newline at end of file