Farmify
Validation via Monoidal, Contravariant functors
Getting Started
npm i --save farmify
Once you've installed farmify you can then import the modules you need to do your validation.
Farmify has no constraints on your failure type, so you can easily use simple string values
as shown in this example, or provide your own error type.
// some primitive validation rules // non primitive type // make a primitive validation work for a non primitive type; // combine 0 - many validations into a single validation where// all rules must pass to be valid and all failures are aggregated validatePerson// { kind: "Success" } validatePerson// { kind: "Failure", errors: [ "value required", "not positive" ] }
Using a custom error type
Farmify is polymorphic in its error type which means you can use whatever you want.
; ? success : failure;
Working with asynchronous validation
// an asynchronous validation // a non asynchronous validation ? success : failure validUserName'bob'.thenconsole.log//{ kind: "Success" } validUserName'thisIsTooLong'.thenconsole.log//{ kind: "Failure", errors: [ 'Cannot be longer than 8' ] }