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.

48 lines (41 loc) 1.71 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class; var _chunkXDVSL5B6js = require('./chunk-XDVSL5B6.js'); var _chunkVN4GLOENjs = require('./chunk-VN4GLOEN.js'); // src/asserts/boolean/index.ts var isBoolean = (expected) => (received, ctx) => { if (received !== expected) ctx.addIssue(expected, received, "c:isBoolean"); }; function boolean() { return new BooleanSchema({ type: ["boolean"], requiredValidations: [] }); } var BooleanSchema = (_class = class extends _chunkVN4GLOENjs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); } __init() {this._boolean = 1} /** * @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() { _chunkXDVSL5B6js._setStrictType.call(void 0, this, true); return this.custom(isBoolean(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() { _chunkXDVSL5B6js._setStrictType.call(void 0, this, false); return this.custom(isBoolean(false)); } }, _class); exports.boolean = boolean; //# sourceMappingURL=chunk-2HGS4STD.js.map