path-to-regexp
Advanced tools
Comparing version 0.1.5 to 0.1.6
46
index.js
@@ -8,2 +8,7 @@ /** | ||
/** | ||
* Match matching groups in a regular expression. | ||
*/ | ||
var MATCHING_GROUP_REGEXP = /\((?!\?)/g; | ||
/** | ||
* Normalize the given path string, | ||
@@ -26,2 +31,3 @@ * returning a regular expression. | ||
options = options || {}; | ||
keys = keys || []; | ||
var strict = options.strict; | ||
@@ -31,6 +37,16 @@ var end = options.end !== false; | ||
var extraOffset = 0; | ||
var keysOffset = keys.length; | ||
var i = 0; | ||
var name = 0; | ||
var m; | ||
keys = keys || []; | ||
if (path instanceof RegExp) { | ||
while (m = MATCHING_GROUP_REGEXP.exec(path.source)) { | ||
keys.push({ | ||
name: name++, | ||
optional: false, | ||
offset: m.index | ||
}); | ||
} | ||
if (path instanceof RegExp) { | ||
return path; | ||
@@ -62,4 +78,3 @@ } | ||
optional: !!optional, | ||
index: 0, | ||
_offset: offset + extraOffset | ||
offset: offset + extraOffset | ||
}); | ||
@@ -82,4 +97,4 @@ | ||
while (len-- && keys[len]._offset > index) { | ||
keys[len]._offset += 3; | ||
while (len-- > keysOffset && keys[len].offset > index) { | ||
keys[len].offset += 3; | ||
} | ||
@@ -90,12 +105,13 @@ | ||
// This is a workaround for handling *all* matching group positioning. | ||
var re = /\((?!\?)/g; | ||
var m; | ||
// This is a workaround for handling unnamed matching groups. | ||
while (m = MATCHING_GROUP_REGEXP.exec(path)) { | ||
if (keysOffset + i === keys.length || keys[keysOffset + i].offset > m.index) { | ||
keys.splice(keysOffset + i, 0, { | ||
name: name++, // Unnamed matching groups must be consistently linear. | ||
optional: false, | ||
offset: m.index | ||
}); | ||
} | ||
while (m = re.exec(path)) { | ||
var len = keys.length; | ||
while (len-- && keys[len]._offset > m.index) { | ||
keys[len].index++; | ||
} | ||
i++; | ||
} | ||
@@ -102,0 +118,0 @@ |
{ | ||
"name": "path-to-regexp", | ||
"description": "Express style path to RegExp utility", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"files": [ | ||
@@ -6,0 +6,0 @@ "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6404
98