UNPKG

@stacksjs/ts-validation

Version:

A simple TypeScript starter kit using Bun.

39 lines (34 loc) 948 B
import type { BooleanValidatorType, ValidationNames } from '../types'; export declare class BooleanValidator extends BaseValidator<boolean> implements BooleanValidatorType { public name: ValidationNames = 'boolean' constructor() { super() this.addRule({ name: 'boolean', test: (value: unknown): value is boolean => typeof value === 'boolean', message: 'Must be a boolean', }) } isTrue(): this { return this.addRule({ name: 'isTrue', test: (value: boolean) => value === true, message: 'Must be true', }) } isFalse(): this { return this.addRule({ name: 'isFalse', test: (value: boolean) => value === false, message: 'Must be false', }) } custom(fn: (value: boolean) => boolean, message: string): this { return this.addRule({ name: 'custom', test: fn, message, }) } } export declare function boolean(): BooleanValidator;