Boolean schema
A function which creates a parsing rule to ensure that a given value is a boolean.
Arguments
modifiers?
- A list of modifierscustom
: Learn more
message?
- A custom object with error messages to be displayed when validation fails or there are type errors
Examples
import { boolean } from '@nordic-ui/validathor';
const booleanRule = boolean();
try {
const parsedValue = booleanRule.parse(true);
console.log('Parsed value:', parsedValue);
} catch (error) {
console.error('Parsing failed:', error.message);
}
TypeScript
To get the type of a schema, you can do the following:
const booleanRule = boolean();
type BooleanSchema = ReturnType<typeof booleanRule.parse>; // boolean