path-to-regexp
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "path-to-regexp", | ||
"description": "Express style path to RegExp utility", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"keywords": [ | ||
@@ -14,3 +14,6 @@ "express", | ||
], | ||
"license": "MIT" | ||
} | ||
"license": "MIT", | ||
"dependencies": { | ||
"juliangruber/isarray": "0.0.1" | ||
} | ||
} |
45
index.js
@@ -0,1 +1,3 @@ | ||
var isArray = require('isarray'); | ||
/** | ||
@@ -43,3 +45,3 @@ * Expose `pathtoRegexp`. | ||
*/ | ||
var attachKeys = function (re, keys) { | ||
function attachKeys (re, keys) { | ||
re.keys = keys; | ||
@@ -62,3 +64,3 @@ | ||
function pathtoRegexp (path, keys, options) { | ||
if (keys && !Array.isArray(keys)) { | ||
if (!isArray(keys)) { | ||
options = keys; | ||
@@ -78,13 +80,15 @@ keys = null; | ||
// Match all capturing groups of a regexp. | ||
var groups = path.source.match(/\((?!\?)/g) || []; | ||
var groups = path.source.match(/\((?!\?)/g); | ||
// Map all the matches to their numeric keys and push into the keys. | ||
keys.push.apply(keys, groups.map(function (match, index) { | ||
return { | ||
name: index, | ||
delimiter: null, | ||
optional: false, | ||
repeat: false | ||
}; | ||
})); | ||
// Map all the matches to their numeric indexes and push into the keys. | ||
if (groups) { | ||
for (var i = 0; i < groups.length; i++) { | ||
keys.push({ | ||
name: i, | ||
delimiter: null, | ||
optional: false, | ||
repeat: false | ||
}); | ||
} | ||
} | ||
@@ -95,12 +99,13 @@ // Return the source back to the user. | ||
if (Array.isArray(path)) { | ||
// Map array parts into regexps and return their source. We also pass | ||
// the same keys and options instance into every generation to get | ||
// consistent matching groups before we join the sources together. | ||
path = path.map(function (value) { | ||
return pathtoRegexp(value, keys, options).source; | ||
}); | ||
// Map array parts into regexps and return their source. We also pass | ||
// the same keys and options instance into every generation to get | ||
// consistent matching groups before we join the sources together. | ||
if (isArray(path)) { | ||
var parts = []; | ||
for (var i = 0; i < path.length; i++) { | ||
parts.push(pathtoRegexp(path[i], keys, options).source); | ||
} | ||
// Generate a new regexp instance by joining all the parts together. | ||
return attachKeys(new RegExp('(?:' + path.join('|') + ')', flags), keys); | ||
return attachKeys(new RegExp('(?:' + parts.join('|') + ')', flags), keys); | ||
} | ||
@@ -107,0 +112,0 @@ |
{ | ||
"name": "path-to-regexp", | ||
"description": "Express style path to RegExp utility", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"scripts": { | ||
@@ -22,3 +22,3 @@ "test": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec" | ||
"type": "git", | ||
"url": "https://github.com/component/path-to-regexp.git" | ||
"url": "https://github.com/pillarjs/path-to-regexp.git" | ||
}, | ||
@@ -28,3 +28,6 @@ "devDependencies": { | ||
"mocha": "~1.21.4" | ||
}, | ||
"dependencies": { | ||
"isarray": "0.0.1" | ||
} | ||
} |
@@ -8,2 +8,5 @@ # Path-to-RegExp | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![Dependency Status][david-image]][david-url] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
@@ -148,5 +151,11 @@ ## Installation | ||
[npm-url]: https://npmjs.org/package/path-to-regexp | ||
[travis-image]: https://img.shields.io/travis/component/path-to-regexp.svg?style=flat | ||
[travis-url]: https://travis-ci.org/component/path-to-regexp | ||
[coveralls-image]: https://img.shields.io/coveralls/component/path-to-regexp.svg?style=flat | ||
[coveralls-url]: https://coveralls.io/r/component/path-to-regexp?branch=master | ||
[travis-image]: https://img.shields.io/travis/pillarjs/path-to-regexp.svg?style=flat | ||
[travis-url]: https://travis-ci.org/pillarjs/path-to-regexp | ||
[coveralls-image]: https://img.shields.io/coveralls/pillarjs/path-to-regexp.svg?style=flat | ||
[coveralls-url]: https://coveralls.io/r/pillarjs/path-to-regexp?branch=master | ||
[david-image]: http://img.shields.io/david/pillarjs/path-to-regexp.svg?style=flat | ||
[david-url]: https://david-dm.org/pillarjs/path-to-regexp | ||
[license-image]: http://img.shields.io/npm/l/path-to-regexp.svg?style=flat | ||
[license-url]: LICENSE.md | ||
[downloads-image]: http://img.shields.io/npm/dm/path-to-regexp.svg?style=flat | ||
[downloads-url]: https://npmjs.org/package/path-to-regexp |
Sorry, the diff of this file is not supported yet
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
34820
1017
160
1
+ Addedisarray@0.0.1
+ Addedisarray@0.0.1(transitive)