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.45 kB
Source Map (JSON)
{"version":3,"sources":["../src/asserts/number/negative.ts"],"sourcesContent":["import { setToDefaultLocale } from '../../translationMap';\nimport type { ExceptionContext, RequiredValidation } from '../../core';\n\nconst negativeErrorMessage = 'The received value is not a negative number';\nconst negativeErrorKey = 'n:negative';\n\n/**\n * @description Asserts that a number value is negative (less than zero).\n * @returns {RequiredValidation} A validation function that takes a received number and an exception context.\n * @throws {ValidationError} if the received value is not negative.\n * @example\n * const schema = number().custom(negative());\n * parseOrFail(schema, -10); // Valid\n * parseOrFail(schema, 0); // Throws an error: 'The received value is not a negative number'\n * parseOrFail(schema, 5); // Throws an error: 'The received value is not a negative number'\n *\n * @translation - Error Translation Key = 'n:negative'\n */\nexport const negative = (): RequiredValidation => (received: number, ctx: ExceptionContext) => {\n if (received >= 0) ctx.addIssue('negative', received, negativeErrorKey);\n};\n\nnegative.key = negativeErrorKey;\nnegative.message = negativeErrorMessage;\nsetToDefaultLocale(negative);\n"],"mappings":";;;;;AAGA,IAAM,uBAAuB;AAC7B,IAAM,mBAAmB;AAclB,IAAM,WAAW,MAA0B,CAAC,UAAkB,QAA0B;AAC7F,MAAI,YAAY,EAAG,KAAI,SAAS,YAAY,UAAU,gBAAgB;AACxE;AAEA,SAAS,MAAM;AACf,SAAS,UAAU;AACnB,mBAAmB,QAAQ;","names":[]}