veto
middleware to validate parameters
install
npm install veto
example
var veto = ; app; app; // an express error handler will receive the thrown errorapp;
things you can veto
- is(regex)
- not(regex)
- isEmail()
- isUrl()
- isIP()
- isAlpha()
- isAlphanumeric()
- isNumeric()
- isInt()
- isDecimal()
- notNull()
- isNull()
- notEmpty()
- equals(equals)
- contains(str)
- notContains(str)
- len(min [, max])
- isUUID(version) //Version can be 3 or 4 or empty
- isIn(arr | str)
- notIn(arr | str)
- max(val)
- min(val)
- isArray()
adding your own
You can add your own things to veto by providing an object to the veto()
. Each ownProperty
of the object which is a function will be added.
this
in the function will refer to the parameter to assert.
To indicate an error, return a string. Otherwise don't return anything.
var additional = { if this !== 'foobar' return 'should equal foobar'; }; app; app;
capturing errors
Veto asserts throw. This means that the error handler middleware will be called as soon as a veto fails. You can easily handle the error there and send any relevant response back to the user.
app; app; // error handler for failed assertionsapp;