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.53 kB
{"version":3,"sources":["../src/asserts/string/upperCase.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst upperCaseErrorMessage = 'The received value is not in uppercase';\nconst upperCaseErrorKey = 's:upperCase';\n\n/**\n * @description Asserts that a string value is entirely in uppercase.\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 uppercase.\n * @example\n * const schema = string().custom(upperCase());\n * parseOrFail(schema, 'VALID'); // Valid\n * parseOrFail(schema, 'INVALID'); // Throws an error: 'The received value is not in uppercase'\n * parseOrFail(schema, 'Valid'); // Throws an error: 'The received value is not in uppercase'\n *\n * @translation Error Translation Key = 's:upperCase'\n */\nexport const upperCase = (): RequiredValidation => (received: string, ctx: ExceptionContext) => {\n if (received !== received.toUpperCase()) {\n ctx.addIssue('upper case', received, upperCaseErrorKey);\n }\n};\n\nupperCase.key = upperCaseErrorKey;\nupperCase.message = upperCaseErrorMessage;\nsetToDefaultLocale(upperCase);\n"],"mappings":";;;;;AAGA,IAAM,wBAAwB;AAC9B,IAAM,oBAAoB;AAcnB,IAAM,YAAY,MAA0B,CAAC,UAAkB,QAA0B;AAC9F,MAAI,aAAa,SAAS,YAAY,GAAG;AACvC,QAAI,SAAS,cAAc,UAAU,iBAAiB;AAAA,EACxD;AACF;AAEA,UAAU,MAAM;AAChB,UAAU,UAAU;AACpB,mBAAmB,SAAS;","names":[]}