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.44 kB
{"version":3,"sources":["../src/asserts/number/min.ts"],"sourcesContent":["import { setToDefaultLocale } from '../../translationMap';\nimport type { ExceptionContext, RequiredValidation } from '../../core';\n\nconst minErrorMessage = 'The received value is less than expected';\nconst minErrorKey = 'n:min';\n\n/**\n * @description Asserts that a number value is not less than a specified minimum value.\n * @param {number} expected The minimum allowable value.\n * @returns {RequiredValidation} A validation function that takes a received number and an exception context.\n * @throws {ValidationError} if the received value is less than the expected minimum value.\n * @example\n * const schema = number().custom(min(10));\n * parseOrFail(schema, 11); // Valid\n * parseOrFail(schema, 10); // Valid\n * parseOrFail(schema, 9); // Throws an error: 'The received value is less than expected'\n *\n * @translation Error Translation Key = 'n:min'\n */\nexport const min =\n (expected: number): RequiredValidation =>\n (received: number, ctx: ExceptionContext) => {\n if (expected > received) ctx.addIssue(expected, received, minErrorKey);\n };\n\nmin.key = minErrorKey;\nmin.message = minErrorMessage;\nsetToDefaultLocale(min);\n"],"mappings":";;;;;AAGA,IAAM,kBAAkB;AACxB,IAAM,cAAc;AAeb,IAAM,MACX,CAAC,aACD,CAAC,UAAkB,QAA0B;AAC3C,MAAI,WAAW,SAAU,KAAI,SAAS,UAAU,UAAU,WAAW;AACvE;AAEF,IAAI,MAAM;AACV,IAAI,UAAU;AACd,mBAAmB,GAAG;","names":[]}