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.

42 lines (39 loc) 1.58 kB
import { WithBGuardType } from '../../commonTypes.mjs'; import { CommonSchema } from '../../core.mjs'; import '../../InferType.mjs'; import '../../helpers/constants.mjs'; /** * @description Creates a new schema for validating boolean values. * @returns {WithBGuardType<BooleanSchema, boolean>} A new instance of `BooleanSchema` for validating booleans. * @example * const schema = boolean(); * parseOrFail(schema, true); // Validates successfully * parseOrFail(schema, 'true'); // Throws a validation error * * @instance Of BooleanSchema */ declare function boolean(): WithBGuardType<BooleanSchema, boolean>; declare class BooleanSchema extends CommonSchema { protected _boolean: number; /** * @method onlyTrue * @description Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type. * @returns The schema instance restricted to the value true, with the true value inferred as the TypeScript type * @example * boolean().onlyTrue(); // Infers the type true * * @public */ onlyTrue(): WithBGuardType<this, true>; /** * @method onlyFalse * @description Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type. * @returns The schema instance restricted to the value false, with the false value inferred as the TypeScript type * @example * boolean().onlyFalse(); // Infers the type false * * @public */ onlyFalse(): WithBGuardType<this, false>; } export { boolean };