Assert utility
assert
is used to check that a condition is truthy, otherwise it'll throw either a ValidationError
or a custom error type.
This function is used within each of our schemas and modifiers
Arguments
condition
The condition to check.message?
The error message to throw if the condition is false.
Example
import { assert } from '@nordic-ui/validathor';
assert(isAdmin === true, 'You must be an admin to perform this action');
// Or
assert(typeof 123 === 'string', new TypeError('Expected a string'));