@fmtk/decoders
v0.5.6
Published
Lightweight, composable validation and serialization library.
Downloads
108
Readme
@fmtk/decoders
Lightweight, composable validation and serialization library.
What's it for?
Typescript lets you check your own code and nothing more. This library lets you check data flowing in and out of code that is under your control.
Show me the code!
The following code creates a validator for an object then prints the results of a validation.
const myModel = object({
greeting: text,
name: text,
age: optional(integer),
});
const result = myModel(getValueFromSomewhere());
if (result.ok) {
console.log(value);
} else {
console.error(result.error);
}
Documentation
See documentation.
Influences
This project is the successor to the @fmtk/validation package which has seen use in numerous Futurematik projects. I wanted to make an API that was a bit clearer in intent compared to the original validation package.
The design of this project has been influenced by the decoders package which I discovered early in the build. I considered abandoning this project in favour of the latter, but I decided I wanted to build a Typescript implementation.