1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.IsMilitaryTime = exports.isMilitaryTime = exports.IS_MILITARY_TIME = void 0;
|
7 | const ValidateBy_1 = require("../common/ValidateBy");
|
8 | const matches_1 = __importDefault(require("validator/lib/matches"));
|
9 | exports.IS_MILITARY_TIME = 'isMilitaryTime';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function isMilitaryTime(value) {
|
15 | const militaryTimeRegex = /^([01]\d|2[0-3]):?([0-5]\d)$/;
|
16 | return typeof value === 'string' && (0, matches_1.default)(value, militaryTimeRegex);
|
17 | }
|
18 | exports.isMilitaryTime = isMilitaryTime;
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function IsMilitaryTime(validationOptions) {
|
24 | return (0, ValidateBy_1.ValidateBy)({
|
25 | name: exports.IS_MILITARY_TIME,
|
26 | validator: {
|
27 | validate: (value, args) => isMilitaryTime(value),
|
28 | defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a valid representation of military time in the format HH:MM', validationOptions),
|
29 | },
|
30 | }, validationOptions);
|
31 | }
|
32 | exports.IsMilitaryTime = IsMilitaryTime;
|
33 |
|
\ | No newline at end of file |