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.

71 lines (69 loc) 2.03 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/bigint/index.ts function bigint() { return new BigIntSchema({ type: ["bigint"], requiredValidations: [] }); } var BigIntSchema = class extends CommonSchema { _bigint = 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 * bigint().equalTo(42n); // Infers the type 42n * * @public */ equalTo(expectedValue) { this.defaultValueCheck(); this.limitCheck(); _setStrictType(this, `${expectedValue}n`); 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 * bigint().oneOfValues([5n, 7n]); // Infers the type 5n | 7n * * @public */ oneOfValues(expectedValue) { this.defaultValueCheck(); this.limitCheck(); _setStrictType( this, expectedValue.map((el) => `${el}n`) ); return this.custom(oneOfValues(expectedValue)); } limitCheck() { if (this.limit) throw new BuildSchemaError(ONLY_ONCE); this.limit = true; } }; export { bigint }; //# sourceMappingURL=chunk-NFD7D5GZ.mjs.map