Skip to content
Myr

use path-to-regexp

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jonathan Ong · committed by Jonathan Ong · parent 5572897 · Browse files · 3 files+5 added−47 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+5 added−47 removed

  • other:+5 added−47 removed

3 files+5 added−47 removed

modified:lib/router/layer.js+4 added-7 removed
modified:lib/utils.js-40 removed
118 unmodified lines
119 return ret;120}121122/**123 * Normalize the given path string,124 * returning a regular expression.125 *126 * An empty array should be passed,127 * which will contain the placeholder128 * key names. For example "/user/:id" will129 * then contain ["id"].130 *131 * @param {String|RegExp|Array} path132 * @param {Array} keys133 * @param {Boolean} sensitive134 * @param {Boolean} strict135 * @param {Boolean} end (whether to append $ to regex)136 * @return {RegExp}137 * @api private138 */139140exports.pathRegexp = function(path, keys, sensitive, strict, end) {141 if (toString.call(path) == '[object RegExp]') return path;142 if (Array.isArray(path)) path = '(' + path.join('|') + ')';143 path = path144 .concat(strict ? '' : '/?')145 .replace(/\/\(/g, '(?:/')146 .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?(\*)?/g, function(_, slash, format, key, capture, optional, star){147 keys.push({ name: key, optional: !! optional });148 slash = slash || '';149 return ''150 + (optional ? '' : slash)151 + '(?:'152 + (optional ? slash : '')153 + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')'154 + (optional || '')155 + (star ? '(/*)?' : '');156 })157 .replace(/([\/.])/g, '\\$1')158 .replace(/\*/g, '(.*)');159 return new RegExp('^' + path + ((end) ? '$' : ''), sensitive ? '' : 'i');160}161162/**123 * Parse the `req` url with memoization.124 *125 * @param {ServerRequest} req126 * @return {Object}
18 unmodified lines
modified:package.json+1 added