Resistor
Resist mass assignment vulnerabilities - map the important bits
Installation
npm install resistor --save
Usage
Middleware
Instead of validating input directly in your route handler resistor will generate a piece of middleware to do the heavy lifting:
var validateSignup = ; router;
Out of the box resistor will send 400 JSON responses if a request is not valid. To modify this behaviour the errorHandler option comes to rescue:
{ res status400 ;} var validateSignup = ; router;
Plain Javascript
To use resistor model binding outside of a middleware context resistor exposes the binder
function to construct a binder
var binder = resistor;var model = binder; console; // prints `value` to stdout
Model binding/validation errors can be accessed by checking the errors
field of the model
var binder = resistor;var model = binder; console; // prints `{ input: [ { validator: 'required', value: undefined } ] }` to stdout