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.

1 lines 1.67 kB
{"version":3,"sources":["../src/asserts/string/uuidV5.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst uuidV5ErrorMessage = 'The received value is not a valid UUID v5';\nconst uuidV5ErrorKey = 's:uuidV5';\n\nconst uuidV5Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\n/**\n * @description Asserts that a string value matches the UUID v5 format.\n * @returns {RequiredValidation} A validation function that takes a received string and an exception context.\n * @throws {ValidationError} if the received value is not a valid UUID v5.\n * @example\n * const schema = string().custom(uuidV5());\n * parseOrFail(schema, '550e8400-e29b-51d4-a716-446655440000'); // Valid\n * parseOrFail(schema, '550e8400-e29b-41d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v5'\n * parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v5'\n *\n * @translation Error Translation Key = 's:uuidV5'\n */\nexport const uuidV5 = (): RequiredValidation => (received: string, ctx: ExceptionContext) => {\n if (!uuidV5Pattern.test(received)) {\n ctx.addIssue('uuid v5', received, uuidV5ErrorKey);\n }\n};\n\nuuidV5.key = uuidV5ErrorKey;\nuuidV5.message = uuidV5ErrorMessage;\nsetToDefaultLocale(uuidV5);\n"],"mappings":";;;;;AAGA,IAAM,qBAAqB;AAC3B,IAAM,iBAAiB;AAEvB,IAAM,gBAAgB;AAcf,IAAM,SAAS,MAA0B,CAAC,UAAkB,QAA0B;AAC3F,MAAI,CAAC,cAAc,KAAK,QAAQ,GAAG;AACjC,QAAI,SAAS,WAAW,UAAU,cAAc;AAAA,EAClD;AACF;AAEA,OAAO,MAAM;AACb,OAAO,UAAU;AACjB,mBAAmB,MAAM;","names":[]}