Additional validation rules / contraints for validate.js to address other common data patterns
vtypes
is built on top of validate.js
, providing additional validation rules for
certain data patterns / data types.
vtypes
is available in a variety of builds & module formats.
All packages by default exposes a module in commonjs
format.
However, a umd
bundle is also available within each package if you prefer that.
i.e. Instead of require('vtypes-*')
use require('vtypes-*/umd')
.
For more information, do check their individual README.md
in their respective folders.
Note: Those listed as yes
in the column Default
will be included
in vtypes
and vtypes-register
packages.
Validator | Default | Description |
---|---|---|
arrayOf | yes | allows recursive validation of an array content |
array | yes | checks for array (empty array is also valid) |
bool | yes | must be of type boolean |
different | yes | must have a different value than the provided field. |
func | yes | must be a type function |
invariant | yes | conditional check based on a truthy result of a function |
json | yes | must be a valid JSON string. |
objectOf | yes | object with property values following a certain validation rule |
only | yes | must be the ONLY ONE present amongst specified attributes |
shape | yes | allows recursive validation of nested object |
string | yes | must be a type string |
Validator | Default | Description |
---|---|---|
immutable | yes | checks for immutable resource |
size | yes | same as the built in "length" validator, but uses "size" instead. |
The following validators are inspired from the built-in validation rules of Laravel
Validator | Default | Description |
---|---|---|
requiredIf | yes | required if the another attribute is present or equal to any value. |
requiredUnless | yes | required unless the another attribute is equal to any value. |
requiredWith | yes | required if ANY of the other specified attributes are present. |
requiredWithAll | yes | required if ALL of the other specified attributes are present. |
requiredWithout | yes | required when ANY of the specified attributes are not present |
requiredWithoutAll | yes | required when ALL of the specified attributes are not present |
vtypes
is MIT licensed