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.52 kB
{"version":3,"sources":["../src/asserts/bigint/bigintMax.ts"],"sourcesContent":["import type { ExceptionContext, RequiredValidation } from '../../core';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst bigintMaxErrorMessage = 'The received value is greater than expected';\nconst bigintMaxErrorKey = 'bi:max';\n\n/**\n * @description Asserts that a bigint value does not exceed a specified maximum value.\n * @param {bigint} expected The maximum allowable value.\n * @returns {RequiredValidation} A validation function that takes a received bigint and an exception context.\n * @throws {ValidationError} if the received value exceeds the expected maximum value.\n * @example\n * const schema = bigint().custom(bigintMax(100n));\n * parseOrFail(schema, 99n); // Valid\n * parseOrFail(schema, 100n); // Valid\n * parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'\n *\n * @translation Error Translation Key = 'bi:max'\n */\nexport const bigintMax =\n (expected: bigint): RequiredValidation =>\n (received: bigint, ctx: ExceptionContext) => {\n if (expected < received) ctx.addIssue(expected, received, bigintMaxErrorKey);\n };\n\nbigintMax.key = bigintMaxErrorKey;\nbigintMax.message = bigintMaxErrorMessage;\nsetToDefaultLocale(bigintMax);\n"],"mappings":";;;;;AAGA,IAAM,wBAAwB;AAC9B,IAAM,oBAAoB;AAenB,IAAM,YACX,CAAC,aACD,CAAC,UAAkB,QAA0B;AAC3C,MAAI,WAAW,SAAU,KAAI,SAAS,UAAU,UAAU,iBAAiB;AAC7E;AAEF,UAAU,MAAM;AAChB,UAAU,UAAU;AACpB,mBAAmB,SAAS;","names":[]}