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.73 kB
Source Map (JSON)
{"version":3,"sources":["../src/asserts/string/atLeastOneUpperChar.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst atLeastOneUpperCharErrorMessage = 'The received value does not contain at least one uppercase character';\nconst atLeastOneUpperCharErrorKey = 's:atLeastOneUpperChar';\n\n/**\n * @description Asserts that a string value contains at least one uppercase character.\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 uppercase character.\n * @example\n * const schema = string().custom(atLeastOneUpperChar());\n * parseOrFail(schema, 'abcDEF'); // Valid\n * parseOrFail(schema, 'abcdef'); // Throws an error: 'The received value does not contain at least one uppercase character'\n *\n * @translation Error Translation Key = 's:atLeastOneUpperChar'\n */\nexport const atLeastOneUpperChar = (): RequiredValidation => (received: string, ctx: ExceptionContext) => {\n const upperCharRegExp = /[A-Z]/;\n if (!upperCharRegExp.test(received))\n ctx.addIssue('at least one uppercase character', received, atLeastOneUpperCharErrorKey);\n};\n\natLeastOneUpperChar.key = atLeastOneUpperCharErrorKey;\natLeastOneUpperChar.message = atLeastOneUpperCharErrorMessage;\nsetToDefaultLocale(atLeastOneUpperChar);\n"],"mappings":";;;;;AAGA,IAAM,kCAAkC;AACxC,IAAM,8BAA8B;AAa7B,IAAM,sBAAsB,MAA0B,CAAC,UAAkB,QAA0B;AACxG,QAAM,kBAAkB;AACxB,MAAI,CAAC,gBAAgB,KAAK,QAAQ;AAChC,QAAI,SAAS,oCAAoC,UAAU,2BAA2B;AAC1F;AAEA,oBAAoB,MAAM;AAC1B,oBAAoB,UAAU;AAC9B,mBAAmB,mBAAmB;","names":[]}