Skip to content

Instantly share code, notes, and snippets.

@johnsmith17th
Last active December 16, 2015 19:49
Show Gist options
  • Save johnsmith17th/5487604 to your computer and use it in GitHub Desktop.
Save johnsmith17th/5487604 to your computer and use it in GitHub Desktop.
Get parameter with key from express request context, a decorator function of value can be pass.
/**
* Wrap express.request.param with decorator.
*
* @param {HttpRequest} req
* @param {String} name
* @param {Function} [decorator]
* @param {Mixed} [defaultValue]
* @returns value of parameter
*/
function param(req, name, decorator, defaultValue) {
var v = req.param(name, defaultValue);
return 'function' == typeof(decorator) ? decorator(v) : v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment