Comparing version 6.5.0 to 6.5.1
{ | ||
"name": "wayfarer", | ||
"version": "6.5.0", | ||
"version": "6.5.1", | ||
"description": "Composable trie based router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,5 +27,5 @@ # wayfarer [![stability][0]][1] | ||
```js | ||
const wayfarer = require('wayfarer') | ||
var wayfarer = require('wayfarer') | ||
const router = wayfarer('/404') | ||
var router = wayfarer('/404') | ||
@@ -35,2 +35,3 @@ router.on('/', () => console.log('/')) | ||
router.on('/:user', (params) => console.log('user is %s', params.user)) | ||
router.on('/wildcard/*', (params) => console.log('wildcard path is %s', params.wildcard)) | ||
@@ -42,2 +43,5 @@ router('tobi') | ||
// => '404 not found' | ||
router('/wildcard/example/path') | ||
// => 'wildcard path is example/path' | ||
``` | ||
@@ -50,4 +54,4 @@ | ||
```js | ||
const r1 = wayfarer() | ||
const r2 = wayfarer() | ||
var r1 = wayfarer() | ||
var r2 = wayfarer() | ||
@@ -64,6 +68,6 @@ r2.on('/child', () => console.log('subrouter trix!')) | ||
```js | ||
const walk = require('wayfarer/walk') | ||
const wayfarer = require('wayfarer') | ||
var walk = require('wayfarer/walk') | ||
var wayfarer = require('wayfarer') | ||
const router = wayfarer() | ||
var router = wayfarer() | ||
router.on('/multiply', (x, y) => x * y) | ||
@@ -73,3 +77,3 @@ router.on('/divide', (x, y) => x / y) | ||
walk(router, (route, cb) => { | ||
const y = 2 | ||
var y = 2 | ||
return function (params, x) { | ||
@@ -76,0 +80,0 @@ return cb(x, y) |
22
trie.js
@@ -21,6 +21,6 @@ var mutate = require('xtend/mutable') | ||
var routes = route.replace(/^\//, '').split('/') | ||
return (function createNode (index, trie) { | ||
var thisRoute = routes[index] | ||
if (thisRoute === undefined) return trie | ||
function createNode (index, trie) { | ||
var thisRoute = (routes.hasOwnProperty(index) && routes[index]) | ||
if (thisRoute === false) return trie | ||
@@ -30,3 +30,3 @@ var node = null | ||
// if node is a name match, set name and append to ':' node | ||
if (!trie.nodes['$$']) { | ||
if (!trie.nodes.hasOwnProperty('$$')) { | ||
node = { nodes: {} } | ||
@@ -43,3 +43,3 @@ trie.nodes['$$'] = node | ||
trie.name = thisRoute.replace(/^:|^\*/, '') | ||
} else if (!trie.nodes[thisRoute]) { | ||
} else if (!trie.nodes.hasOwnProperty(thisRoute)) { | ||
node = { nodes: {} } | ||
@@ -53,3 +53,5 @@ trie.nodes[thisRoute] = node | ||
return createNode(index + 1, node) | ||
})(0, this.trie) | ||
} | ||
return createNode(0, this.trie) | ||
} | ||
@@ -66,3 +68,3 @@ | ||
var node = (function search (index, trie) { | ||
function search (index, trie) { | ||
// either there's no match, or we're done searching | ||
@@ -73,3 +75,3 @@ if (trie === undefined) return undefined | ||
if (trie.nodes[thisRoute]) { | ||
if (trie.nodes.hasOwnProperty(thisRoute)) { | ||
// match regular routes first | ||
@@ -90,4 +92,6 @@ return search(index + 1, trie.nodes[thisRoute]) | ||
} | ||
})(0, this.trie) | ||
} | ||
var node = search(0, this.trie) | ||
if (!node) return undefined | ||
@@ -94,0 +98,0 @@ node = xtend(node) |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14981
184
154
0