UNPKG

bguard

Version:

**bguard** is a powerful, flexible, and type-safe validation library for TypeScript. It allows developers to define validation schemas for their data structures and ensures that data conforms to the expected types and constraints.

30 lines (25 loc) 1.03 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunkTJQ5NVL4js = require('./chunk-TJQ5NVL4.js'); // src/asserts/string/isValidTime.ts var timeErrorMessage = "The received value is not a valid time"; var timeErrorKey = "s:isValidTime"; var isValidTime = (options = {}) => { return (received, ctx) => { const { precision } = options; let timeRegex = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)(\.\d+)?$/; if (precision !== void 0) { timeRegex = new RegExp(`^([01]\\d|2[0-3]):([0-5]\\d):([0-5]\\d)(\\.\\d{${precision}})?$`); } if (!timeRegex.test(received)) { ctx.addIssue(received, timeErrorMessage, timeErrorKey); } if (precision !== void 0 && !received.includes(".")) { ctx.addIssue(received, timeErrorMessage, timeErrorKey); } }; }; isValidTime.key = timeErrorKey; isValidTime.message = timeErrorMessage; _chunkTJQ5NVL4js.setToDefaultLocale.call(void 0, isValidTime); exports.isValidTime = isValidTime; //# sourceMappingURL=chunk-6LPQRAFN.js.map