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.74 kB
Source Map (JSON)
{"version":3,"sources":["../src/asserts/number/maxExcluded.ts"],"sourcesContent":["import { setToDefaultLocale } from '../../translationMap';\nimport type { ExceptionContext, RequiredValidation } from '../../core';\n\nconst maxExcludedErrorMessage = 'The received value is greater than or equal to expected';\nconst maxExcludedErrorKey = 'n:maxExcluded';\n\n/**\n * @description - Asserts that a number value is strictly less than a specified maximum value (i.e., the maximum value is excluded).\n * @param {number} expected - The maximum allowable value, which is excluded.\n * @returns {RequiredValidation} - A validation function that takes a received number and an exception context.\n * @throws {ValidationError} if the received value is greater than or equal to the expected maximum value.\n * @example\n * const schema = number().custom(maxExcluded(100));\n * parseOrFail(schema, 99); // Valid\n * parseOrFail(schema, 100); // Throws an error: 'The received value is greater than or equal to expected'\n * parseOrFail(schema, 101); // Throws an error: 'The received value is greater than or equal to expected'\n *\n * @translation Error Translation Key = 'n:maxExcluded'\n */\nexport const maxExcluded =\n (expected: number): RequiredValidation =>\n (received: number, ctx: ExceptionContext) => {\n if (expected <= received) ctx.addIssue(expected, received, maxExcludedErrorKey);\n };\n\nmaxExcluded.key = maxExcludedErrorKey;\nmaxExcluded.message = maxExcludedErrorMessage;\nsetToDefaultLocale(maxExcluded);\n"],"mappings":";;;;;AAGA,IAAM,0BAA0B;AAChC,IAAM,sBAAsB;AAerB,IAAM,cACX,CAAC,aACD,CAAC,UAAkB,QAA0B;AAC3C,MAAI,YAAY,SAAU,KAAI,SAAS,UAAU,UAAU,mBAAmB;AAChF;AAEF,YAAY,MAAM;AAClB,YAAY,UAAU;AACtB,mBAAmB,WAAW;","names":[]}