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.
47 lines (44 loc) • 1.93 kB
text/typescript
import { WithBGuardType } from '../../commonTypes.mjs';
import { CommonSchema } from '../../core.mjs';
import '../../InferType.mjs';
import '../../helpers/constants.mjs';
/**
* @description - Creates a new schema for validating bigint values.
* @returns {WithBGuardType<BigIntSchema, bigint>} A new instance of `BigIntSchema` for validating bigints.
* @example
* const schema = bigint();
* parseOrFail(schema, 42n); // Validates successfully
* parseOrFail(schema, 42); // Throws a validation error
* parseOrFail(schema, '42'); // Throws a validation error
*
* @instance Of BigIntSchema
*/
declare function bigint(): WithBGuardType<BigIntSchema, bigint>;
declare class BigIntSchema extends CommonSchema {
protected _bigint: number;
private 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<Y extends bigint>(expectedValue: Y): WithBGuardType<this, Y>;
/**
* @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<Y extends bigint>(expectedValue: Y[]): WithBGuardType<this, Y>;
private limitCheck;
}
export { bigint };