Assert that a value passes the struct's validation, throwing if it doesn't.
Optional
message: stringCreate a value with the struct's coercion logic, then validate it.
Optional
message: stringMask a value, coercing and validating it, but returning only the subset of
properties defined by the struct's schema. Masking applies recursively to
props of object
structs only.
Optional
message: stringValidate a value with the struct's validation logic, returning a tuple representing the result.
You may optionally pass true
for the coerce
argument to coerce
the value before attempting to validate it. If you do, the result will
contain the coerced result when successful. Also, mask
will turn on
masking of the unknown object
props recursively if passed.
Optional
options: { coerce?: boolean; mask?: boolean; message?: string }
Struct
objects encapsulate the validation logic for a specific type of values. Once constructed, you use theassert
,is
orvalidate
helpers to validate unknown input data against the struct.