A validator accepting any value.
Error carrying a structured validation Trace.
Constrains numbers to integral values.
Constrains string length.
Constrains strings to a pattern.
Constrains strings to normalised whitespace.
Constrains numbers and strings to an exclusive lower bound.
Constrains numbers and strings to an inclusive lower bound.
Constrains numbers and strings to an exclusive upper bound.
Constrains numbers and strings to an inclusive upper bound.
Constrains numbers and strings to an enumerated domain.
Constrains an array.
Constrains an object.
Constrains an entry.
Constrains the size of an array or object.
Requires keys to be present in an array or object.
Requires values to be present in an array or object.
Constrains a value with a custom predicate that words its own violation.
Rejects every value.
Requires a value to be present.
Makes a validator tolerant of absent values.
Makes a validator tolerant of null values.
Requires every validator to pass.
Requires at least one validator to pass.
Requires exactly one validator to pass.
Constrains a value by type.
Composable value validators.
Provides composable validators for declaring value constraints. Checks nest to mirror the shape of the data and apply as a single expression, so no traversal or branching need be written by hand. A run reports every violation the value incurs at once, as a Trace keyed to mirror the value itself, diagnosing a failure in full rather than one error at a time.
Constraining Numbers
Restrict numbers to integral values:
Constraining Strings
Restrict strings by length, pattern, or whitespace:
Constraining Literals
Restrict numbers and strings alike, each compared by its own natural ordering:
Constraining Arrays
Restrict the array and its items in one call:
Constraining Objects
Restrict the object and its entries in one call:
Constraining Other Values
Adapt an arbitrary predicate to cover whatever the built-in vocabulary doesn't, reporting either a fixed message or one computed from the rejected value; reject outright to close a branch reached only by values already known to be illegal:
Combining Validators
Assemble validators into compound checks, bottoming out in pass, the constant admitting anything:
Validators key the violations they report by the part of the value incurring them, so a nested check already yields a navigable report; name a violation of your own by prefixing the message handed to fail or test with a facet of its own, in braces.
Every validator slot is Modal, so a check may be switched off inline with a guard expression, without rebuilding the surrounding composition conditionally:
Composing Complex Validators
Nest the above into a deep check, end to end: literal, array, and object constraints combined under a single validator, applied to a value, and reported to callers as a TraceError:
A failing run reports every violated constraint at once, keyed by property and by element position, each message naming the constraint that incurred it: