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.39 kB
Source Map (JSON)
{"version":3,"sources":["../src/asserts/string/lowerCase.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst lowerCaseErrorMessage = 'The received value is not in lowercase';\nconst lowerCaseErrorKey = 's:lowerCase';\n\n/**\n * @description Asserts that a string value is in lowercase.\n * @returns {RequiredValidation} A validation function that takes a received string and an exception context.\n * @throws {ValidationError} if the received value is not in lowercase.\n * @example\n * const schema = string().custom(lowerCase());\n * parseOrFail(schema, 'valid'); // Valid\n * parseOrFail(schema, 'Invalid'); // Throws an error: 'The received value is not in lowercase'\n *\n * @translation Error Translation Key = 's:lowerCase'\n */\nexport const lowerCase = (): RequiredValidation => (received: string, ctx: ExceptionContext) => {\n if (received !== received.toLowerCase()) ctx.addIssue('lower case', received, lowerCaseErrorKey);\n};\n\nlowerCase.key = lowerCaseErrorKey;\nlowerCase.message = lowerCaseErrorMessage;\nsetToDefaultLocale(lowerCase);\n"],"mappings":";;;;;AAGA,IAAM,wBAAwB;AAC9B,IAAM,oBAAoB;AAanB,IAAM,YAAY,MAA0B,CAAC,UAAkB,QAA0B;AAC9F,MAAI,aAAa,SAAS,YAAY,EAAG,KAAI,SAAS,cAAc,UAAU,iBAAiB;AACjG;AAEA,UAAU,MAAM;AAChB,UAAU,UAAU;AACpB,mBAAmB,SAAS;","names":[]}