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.
33 lines (30 loc) • 1.33 kB
TypeScript
import { RequiredValidation } from '../../core.js';
import '../../commonTypes.js';
import '../../InferType.js';
import '../../helpers/constants.js';
interface IsValidTimeOptions {
precision?: number;
}
/**
* @description Asserts that a string is a valid time in the format HH:mm:ss, with optional fractional seconds.
* @param {IsValidTimeOptions} options Optional settings to configure the validation.
* @returns {RequiredValidation} A validation function that takes a received string and an exception context.
* @throws {ValidationError} if the received string is not a valid time.
* @example
* const schema = string().custom(isValidTime());
* parseOrFail(schema, "00:00:00"); // Valid
* parseOrFail(schema, "23:59:59.9999999"); // Valid
* parseOrFail(schema, "00:00:00.256Z"); // Throws an error: 'The received value is not a valid time'
*
* const schemaWithPrecision = string().custom(isValidTime({ precision: 3 }));
* parseOrFail(schemaWithPrecision, "00:00:00.256"); // Valid
* parseOrFail(schemaWithPrecision, "00:00:00"); // Throws an error: 'The received value is not a valid time'
*
* @translation Error Translation Key = 's:isValidTime'
*/
declare const isValidTime: {
(options?: IsValidTimeOptions): RequiredValidation;
key: string;
message: string;
};
export { isValidTime };