@normed/refinements v0.9.0
Refinements
Guard unknown data with refinement calls. Typescript compatible.
This is a typescript compatible full pass composable refinement module, based on the premise that a refinement function is of the form <T>(path: Array<string>, v: mixed): T | RefinementError
.
Here the unknown value v
is refined to the type T
. If the refinement fails a RefinementError
is returned. The path
argument is used to provide a better contextual understanding of where a refinement error occurred.
Refinement functions are commonly called via the provided attemptRefine
or useRefine
functions. attemptRefine
is of the form <T>(RefinementFunction<T>, path: Array<string>, v: any, fallback: T) => T
, while useRefine
is of the form <T>(RefinementFunction<T>) => (path: Array<string>, v: any) => T
Standard refinement functions and refinement utility functions are provided.
Development
yarn run build
yarn run format
yarn run publish