Skip to content

Commit

Permalink
exports: return only regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
logicalparadox committed Dec 10, 2012
1 parent e7ce725 commit ce9fde4
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/parsePath.js
@@ -1,16 +1,14 @@

module.exports = function (path, opts) {
module.exports = function (path, keys, opts) {
keys = keys || [];
opts = opts || {};
var keys = []
, parsed = path
, re = /(\.)?:(\w+)(\?)?/g;
var re = /(\.)?:(\w+)(\?)?/g;

parsed = parsed
path = path
.split(/\//g)
.map(function (chunk) {
return chunk.replace(re, function (_, ext, key, optional) {
if (key) keys.push({ key: key, optional: !! optional });

return ext
? '(?:\.([^/.]+?))' + (optional || '')
: '(?:([^/]+?))' + (optional || '');
Expand All @@ -20,9 +18,5 @@ module.exports = function (path, opts) {
.replace(/([\/.])/g, '\\$1')
.replace(/\*/g, '(.*)');

return {
path: path
, keys: keys
, regexp: new RegExp('^' + parsed + '$', 'i')
};
return new RegExp('^' + path + '$', 'i')
};

0 comments on commit ce9fde4

Please sign in to comment.