find-my-way
Advanced tools
Comparing version 1.6.0 to 1.6.1
24
index.js
@@ -206,16 +206,16 @@ 'use strict' | ||
var handle = currentNode.getHandler(method) | ||
if (!handle) return null | ||
if (handle) { | ||
var paramNames = handle.params | ||
var paramsObj = {} | ||
var paramNames = handle.params | ||
var paramsObj = {} | ||
for (i = 0; i < paramNames.length; i++) { | ||
paramsObj[paramNames[i]] = params[i] | ||
} | ||
for (i = 0; i < paramNames.length; i++) { | ||
paramsObj[paramNames[i]] = params[i] | ||
return { | ||
handler: handle.handler, | ||
params: paramsObj, | ||
store: handle.store | ||
} | ||
} | ||
return { | ||
handler: handle.handler, | ||
params: paramsObj, | ||
store: handle.store | ||
} | ||
} | ||
@@ -232,3 +232,3 @@ | ||
node = currentNode.find(path[0]) | ||
node = currentNode.find(path[0], method) | ||
if (!node) return null | ||
@@ -235,0 +235,0 @@ kind = node.kind |
15
node.js
@@ -45,6 +45,8 @@ 'use strict' | ||
Node.prototype.find = function (label) { | ||
// Check in two different places the numberOfChildren and the map object | ||
// gives us around ~5% more speed | ||
Node.prototype.find = function (label, method) { | ||
for (var i = 0; i < this.numberOfChildren; i++) { | ||
var child = this.children[i] | ||
if (child.map || child.children.length) { | ||
if (child.numberOfChildren !== 0) { | ||
if (child.label === label && child.kind === 0) { | ||
@@ -57,2 +59,11 @@ return child | ||
} | ||
if (child.map && child.map[method]) { | ||
if (child.label === label && child.kind === 0) { | ||
return child | ||
} | ||
if (child.kind > 0) { | ||
return child | ||
} | ||
} | ||
} | ||
@@ -59,0 +70,0 @@ return null |
{ | ||
"name": "find-my-way", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "Crazy fast http radix based router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -64,10 +64,10 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/a/' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a//' }, null) | ||
}) | ||
test('Should be 404 / 4', t => { | ||
test('Should get an empty parameter', t => { | ||
t.plan(1) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.pass('Everything good') | ||
t.fail('We should not be here') | ||
} | ||
@@ -77,6 +77,6 @@ }) | ||
findMyWay.on('GET', '/a/:param', (req, res, params) => { | ||
t.fail('We should not be here') | ||
t.equal(params.param, '') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/a//' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/' }, null) | ||
}) |
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
58607
20
1696