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.
27 lines (24 loc) • 1.2 kB
TypeScript
import { RequiredValidation } from '../../core.js';
import '../../commonTypes.js';
import '../../InferType.js';
import '../../helpers/constants.js';
/**
* @description Asserts that a string value matches the UUID v4 format.
* @returns {RequiredValidation} A validation function that takes a received string and an exception context.
* @throws {ValidationError} if the received value is not a valid UUID v4.
* @example
* const schema = string().custom(uuidV4());
* parseOrFail(schema, '123e4567-e89b-42d3-a456-426614174000'); // Valid
* parseOrFail(schema, '123e4567-e89b-12d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
* parseOrFail(schema, '123e4567-e89b-a2d3-a456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
* parseOrFail(schema, '123e4567-e89b-42d3-c456-426614174000'); // Throws an error: 'The received value is not a valid UUID v4'
* parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v4'
*
* @translation Error Translation Key = 's:uuidV4'
*/
declare const uuidV4: {
(): RequiredValidation;
key: string;
message: string;
};
export { uuidV4 };