Created
February 12, 2014 02:38
-
-
Save jdavisclark/8949030 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var util = require('./util'); | |
| module.exports = function(jsgiReq) { | |
| return Object.create(jsgiReq, { | |
| isXMLHttpRequest: getter(function() { | |
| return !util.no(this.headers['x-requested-with']); | |
| }), | |
| _paramGroups: { | |
| routeParams: { | |
| value: {}, | |
| enumerable: true | |
| }, | |
| search: getter(function() { | |
| return util.extractSearch(jsgiReq); | |
| }) | |
| }, | |
| params: getter(function() { | |
| var tmp = {}, self = this; | |
| Object.keys(this._paramGroups).forEach(function(group) { | |
| tmp = util.merge(tmp, self._paramGroups[group]) | |
| }); | |
| return tmp; | |
| }) | |
| }); | |
| }; | |
| /** | |
| * Helper function to create property descriptor that is enumerable | |
| * and has a getter. | |
| * | |
| * @param fn {Function} The getter function. | |
| * @api private | |
| */ | |
| function getter(fn) { | |
| return { | |
| get: fn, | |
| enumerable: true | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment