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
Source Map (JSON)
{"version":3,"sources":["../src/asserts/string/uuidV1.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst uuidV1ErrorMessage = 'The received value is not a valid UUID v1';\nconst uuidV1ErrorKey = 's:uuidV1';\n\nconst uuidV1Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-1[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 v1 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 v1.\n * @example\n * const schema = string().custom(uuidV1());\n * parseOrFail(schema, '550e8400-e29b-11d4-a716-446655440000'); // Valid\n * parseOrFail(schema, '550e8400-e29b-21d4-a716-446655440000'); // Throws an error: 'The received value is not a valid UUID v1'\n * parseOrFail(schema, 'invalid-uuid'); // Throws an error: 'The received value is not a valid UUID v1'\n *\n * @translation Error Translation Key = 's:uuidV1'\n */\nexport const uuidV1 = (): RequiredValidation => (received: string, ctx: ExceptionContext) => {\n if (!uuidV1Pattern.test(received)) {\n ctx.addIssue('uuid v1', received, uuidV1ErrorKey);\n }\n};\n\nuuidV1.key = uuidV1ErrorKey;\nuuidV1.message = uuidV1ErrorMessage;\nsetToDefaultLocale(uuidV1);\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":[]}