flow-validator
Object validation with proper flow types and more.
Installation
npm install flow-validator
Usage
;; ;
if you do not want import the entire library, you can find single validators in
import { object } from 'flow-validator/sync/object';
or
import { asyncArrayOf } from 'flow-validator/async/asyncArrayOf';
Implemented types / combinators
Type | Flow syntax | Runtime type |
---|---|---|
string | string |
string |
number | number |
number |
boolean | boolean |
boolean |
generic object | Object |
objectType |
generic function | Function |
Function |
instance of C |
C |
instanceOf(C) |
class of C |
Class<C> |
classOf(C) |
array | Array<A> |
arrayOf(A) |
intersection | A & B |
intersection(A, B) |
union | A | B |
union(A, B) |
literal | 's' |
literal('s') |
optional | ?A |
optional(A) |
map | { [key: A]: B } |
mapping(A, B) |
refinement | ✘ | number.refine(n => { if (n > 10) return n; throw new Error(); }) |
object | { name: string } |
object({ name: string }) |
exact object | {| name: string |} |
objectExact({ name: string }) |
null | null |
isNull |
undefined | void |
isUndefined |
not checked | any |
isAny |
all types | mixed |
isMixed |
function | (a: A) => B |
takes(A)(returns(B)(...)) |
Included refinements
Type | Refinements | Transformations |
---|---|---|
string | .isEmail() .isValidDate() .minLength() .maxLength() .regexp() |
.toDate() |
Technical documentation
for older versions:
git clone https://github.com/freddi301/flow-validator.git
cd flow-validator
yarn
npm run doc:serve
Feature Requests Wanted
(open issue, include examples or links)
Inspiration
flow-io (checkout io-ts too for typescript)
Alternatives
Other Alternatives - not flow typed
Planned Features
- 0.7.0
- include https://github.com/hapijs/joi/blob/master/API.md features see TODO.md
- extend()
- typescript support
- 0.8.0
- generate documentation from types (md, html, jsonschema, blueprint, mson, graphql-schema)
- generate flow-validator validators from flow annotations, jsonschema and graphql-schema (cli, runtime, compiletime, startuptime)
- json schema validation
- 0.9.0
- refactor validators to contain metadata
- refactor errors to contain metadata
- write visitors for validators and errors
- write default interpreters for errors json and optionally localized text
- 1.0.0
- test 100%
- doc examples for all validators
- better flow coverage where possible
- readme += new type example
- 2.0.0
- doc 100%
- performance comparison (compete with https://github.com/ebdrup/json-schema-benchmark)
- optimize, use lodash, cache optional() singleton and frequently used types
Experimental
- readme += alternate use: json graphql alternative
- rewrite match
- Vmatch asyncMatch asyncVmatch
- overloading
- monad do notation using row polymorphism
- auto row currying (aka builder)
- literal values
Other
- move documentation to surge.sh