KISSchema
ReactJS propType-inspired schemas for plain old JS objects.
Example:
var emailType = types var userSchema = name: typesstringisRequired email: emailTypeisRequired age: typesnumber friends: types // => passes.. returns null // => passes.. returns null // => fails.. returns array of error messages about incorrect friends array
Types includes all those present in React.PropTypes, with the exception of React-specific types: node and element.
In addition, our custom type is a bit more involved, requiring validate and error message functions:
var shoutType = types
API
- types.string
- types.number
- types.bool
- types.func
- types.array
- types.object
- types.oneOf
- types.oneOfType
- types.shape
- types.arrayOf
- types.objectOf
any of the above types can be followed with .isRequired
- validate(schema, obj, opts={})
- returns null if passes, or an array of error messages if doesn't pass
opts
can include the following propsfailFast
- Stops validating on the first error