Traversal API
| Name | Summary | Notes & Examples |
|---|---|---|
| path | the path being validated or morphed | â array indices represented as numbers â ïž mutated during traversal - use |
| errors | ArkErrors that will be part of this traversal's finalized result | â will always be an empty array for a valid traversal |
| root | the original value being traversed | |
| config | configuration for this traversal | â options can affect traversal results and error messages â defaults < global config < scope config â does not include options configured on individual types |
| reject | add an ArkErrorand return | â
useful for predicates like |
| mustBe | add an ArkErrorfrom a description and return | â
useful for predicates like |
| error | add and return an ArkError | â
useful for morphs like |
| hasError | whether currentBranch(or the traversal root, outside a union) has one or more errors |
assert
Validate data, returning the output on success or throwing a TraversalError on failure:
allows
Check if data satisfies the type's constraints without applying morphs or transformations. Returns a type guard:
This is useful when you want a pure type check without triggering any side effects from morphs like string.numeric.parse.
Invoking a Type directly
Calling a Type as a function validates and transforms the input, returning either the output or ArkErrors:
ArkErrors
The ArkErrors array returned on validation failure contains ArkError instances with structured data:
TraversalError
When .assert() fails, it throws a TraversalError (extends Error) with:
- A formatted
message(single errors inline, multiple errors bulleted) - A non-enumerable
arkErrorsproperty for programmatic access