Skip to content

Instantly share code, notes, and snippets.

@andyburke
Last active May 21, 2016 02:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyburke/7dcd251cca2c9ef1cf5f73417b4d028c to your computer and use it in GitHub Desktop.
Save andyburke/7dcd251cca2c9ef1cf5f73417b4d028c to your computer and use it in GitHub Desktop.
parameterizer concept
const boolean = require( 'boolean' );
...
// look at object-transmute as a helper for implementing this
parameterizer( [ {
inputs: [ 'limit', 'max' ],
output: 'limit',
default: 10,
min: 1,
max: 100,
process: value => {
return value / 10;
},
validate: value => {
return typeof value === 'number';
}
}, {
inputs: [ 'foo', 'foo2' ],
output: 'foo',
default: false,
process: value => {
return boolean( value );
}
} ], [
request.params,
request.query,
request.headers
], ( error, params ) => {
if ( error ) {
response.send( error.status || 500, error );
return;
}
// params...
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment