Schema - Boolean
The .boolean
method is used to validate whether a given value is of type boolean
. It ensures that the input is either true
or false
, making it useful for validating data like toggle states, flags, or any binary value.
This method is essential for enforcing strict type validation where only Boolean values are acceptable.
Example
Below is an example of how to use .boolean
to validate whether a value is a valid Boolean:
import { schema } from "vkrun"
const exampleSchema = schema().boolean()
const validateA = exampleSchema.validate(false) // Valid Boolean
const validateB = exampleSchema.validate("false") // Invalid, string is not a Boolean
console.log(validateA) // true
console.log(validateB) // false