UNPKG

1.59 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.IsMilitaryTime = exports.isMilitaryTime = exports.IS_MILITARY_TIME = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const matches_1 = __importDefault(require("validator/lib/matches"));
9exports.IS_MILITARY_TIME = 'isMilitaryTime';
10/**
11 * Checks if the string represents a time without a given timezone in the format HH:MM (military)
12 * If the given value does not match the pattern HH:MM, then it returns false.
13 */
14function 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}
18exports.isMilitaryTime = isMilitaryTime;
19/**
20 * Checks if the string represents a time without a given timezone in the format HH:MM (military)
21 * If the given value does not match the pattern HH:MM, then it returns false.
22 */
23function 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}
32exports.IsMilitaryTime = IsMilitaryTime;
33//# sourceMappingURL=IsMilitaryTime.js.map
\No newline at end of file