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.58 kB
{"version":3,"sources":["../src/asserts/string/atLeastOneDigit.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst digitRegExp = /\\d/;\nconst atLeastOneDigitErrorMessage = 'The received value does not contain at least one digit';\nconst atLeastOneDigitErrorKey = 's:atLeastOneDigit';\n\n/**\n * @description Asserts that a string value contains at least one digit.\n * @returns {RequiredValidation} A validation function that takes a received string and an exception context.\n * @throws {ValidationError} if the received value does not contain at least one digit.\n * @example\n * const schema = string().custom(atLeastOneDigit());\n * parseOrFail(schema, 'abc123'); // Valid\n * parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one digit'\n *\n * @translation Error Translation Key = 's:atLeastOneDigit'\n */\nexport const atLeastOneDigit = (): RequiredValidation => (received: string, ctx: ExceptionContext) => {\n if (!digitRegExp.test(received)) ctx.addIssue('at least one digit', received, atLeastOneDigitErrorKey);\n};\n\natLeastOneDigit.key = atLeastOneDigitErrorKey;\natLeastOneDigit.message = atLeastOneDigitErrorMessage;\nsetToDefaultLocale(atLeastOneDigit);\n"],"mappings":";;;;;AAGA,IAAM,cAAc;AACpB,IAAM,8BAA8B;AACpC,IAAM,0BAA0B;AAazB,IAAM,kBAAkB,MAA0B,CAAC,UAAkB,QAA0B;AACpG,MAAI,CAAC,YAAY,KAAK,QAAQ,EAAG,KAAI,SAAS,sBAAsB,UAAU,uBAAuB;AACvG;AAEA,gBAAgB,MAAM;AACtB,gBAAgB,UAAU;AAC1B,mBAAmB,eAAe;","names":[]}