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.63 kB
Source Map (JSON)
{"version":3,"sources":["../src/asserts/string/endsWith.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst endsWithErrorMessage = 'The received value does not end with the required substring';\nconst endsWithErrorKey = 's:endsWith';\n\n/**\n * @description Asserts that a string value ends with a specified substring.\n * @param {string} substring The substring that the string value must end with.\n * @returns {RequiredValidation} A validation function that takes a received string and an exception context.\n * @throws {ValidationError} if the received value does not end with the required substring.\n * @example\n * const schema = string().custom(endsWith('bar'));\n * parseOrFail(schema, 'foobar'); // Valid\n * parseOrFail(schema, 'foofoo'); // Throws an error: 'The received value does not end with the required substring'\n *\n * @translation Error Translation Key = 's:endsWith'\n */\nexport const endsWith =\n (substring: string): RequiredValidation =>\n (received: string, ctx: ExceptionContext) => {\n if (!received.endsWith(substring)) {\n ctx.addIssue(`ends with '${substring}'`, received, endsWithErrorKey);\n }\n };\n\nendsWith.key = endsWithErrorKey;\nendsWith.message = endsWithErrorMessage;\nsetToDefaultLocale(endsWith);\n"],"mappings":";;;;;AAGA,IAAM,uBAAuB;AAC7B,IAAM,mBAAmB;AAclB,IAAM,WACX,CAAC,cACD,CAAC,UAAkB,QAA0B;AAC3C,MAAI,CAAC,SAAS,SAAS,SAAS,GAAG;AACjC,QAAI,SAAS,cAAc,SAAS,KAAK,UAAU,gBAAgB;AAAA,EACrE;AACF;AAEF,SAAS,MAAM;AACf,SAAS,UAAU;AACnB,mBAAmB,QAAQ;","names":[]}