Last active
May 21, 2016 02:05
-
-
Save andyburke/7dcd251cca2c9ef1cf5f73417b4d028c to your computer and use it in GitHub Desktop.
parameterizer concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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