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.

64 lines (62 loc) 1.93 kB
import { oneOfValues } from "./chunk-W3U7RYLP.mjs"; import { equalTo } from "./chunk-4ZKU4RJL.mjs"; import { _setStrictType } from "./chunk-THU5VBSO.mjs"; import { CommonSchema } from "./chunk-QIPGUTIG.mjs"; import { BuildSchemaError } from "./chunk-ZTCXXAKD.mjs"; import { ONLY_ONCE } from "./chunk-2ANPCB4O.mjs"; // src/asserts/number/index.ts function number() { return new NumberSchema({ type: ["number"], requiredValidations: [] }); } var NumberSchema = class extends CommonSchema { _number = 1; limit; /** * @method equalTo * @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type. * @param expectedValue - The value that the schema must exactly match. * @returns The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type * @example * number().equalTo(42); // Infers the type 42 * * @public */ equalTo(expectedValue) { if (this.limit) throw new BuildSchemaError(ONLY_ONCE); this.limit = true; _setStrictType(this, expectedValue); return this.custom(equalTo(expectedValue)); } /** * @method oneOfValues * @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type. * @param expectedValues - An array of values that the schema can match. * @returns The schema instance restricted to one of the specified values, with the union of those values inferred as the TypeScript type. * @example * number().oneOfValues([5, 7]); // Infers the type 5 | 7 * * @public */ oneOfValues(expectedValue) { if (this.limit) throw new BuildSchemaError(ONLY_ONCE); this.limit = true; _setStrictType(this, expectedValue); return this.custom(oneOfValues(expectedValue)); } }; export { number }; //# sourceMappingURL=chunk-OZ3BTSSQ.mjs.map