url-router
Advanced tools
Comparing version 10.0.0-0 to 10.0.0
@@ -14,5 +14,5 @@ { | ||
], | ||
"program": "${workspaceFolder}\\test\\index.js" | ||
"program": "${workspaceFolder}/test/index.js" | ||
} | ||
] | ||
} |
@@ -105,7 +105,7 @@ 'use strict'; | ||
if (match) { | ||
if (child.param) { | ||
params[child.param] = match[0]; | ||
} | ||
if (match[0].length === remain.length && child.handler) { | ||
if (child.param) { | ||
params[child.param] = match[0]; | ||
} | ||
if (match[0].length === remain.length) { | ||
return { | ||
@@ -119,2 +119,6 @@ handler: child.handler, | ||
if (result) { | ||
if (child.param) { | ||
params[child.param] = match[0]; | ||
} | ||
return result | ||
@@ -121,0 +125,0 @@ } |
{ | ||
"name": "url-router", | ||
"version": "10.0.0-0", | ||
"version": "10.0.0", | ||
"description": "A Trie-based router", | ||
@@ -5,0 +5,0 @@ "main": "dist/URLRouter", |
@@ -17,27 +17,82 @@ # url-router | ||
['/foo', 1], | ||
['/user/:id', 2], | ||
['/user/:id/:page', 3], | ||
['/people/:name(\\w+)', 4], | ||
['(.*)', 5] | ||
['/foo/bar', 2], | ||
['/user/:id', 3], | ||
['/user/:id/:page', 4], | ||
['/people/:name(\\w+)', 5], | ||
['(.*)', 6], | ||
['/:year(\\d+)-:month(\\d+)', 7] | ||
) | ||
let r | ||
r = router.find('/foo') | ||
assert.strictEqual(r.handler, 1) | ||
assert.deepStrictEqual( | ||
router.find('/foo'), | ||
r = router.find('/user/123') | ||
assert.strictEqual(r.handler, 2) | ||
assert.strictEqual(r.params.id, '123') | ||
{ | ||
handler: 1, | ||
params: {} | ||
} | ||
) | ||
r = router.find('/user/456/articles') | ||
assert.strictEqual(r.handler, 3) | ||
assert.strictEqual(r.params.id, '456') | ||
assert.strictEqual(r.params.page, 'articles') | ||
assert.deepStrictEqual( | ||
router.find('/foo/bar'), | ||
r = router.find('/people/john') | ||
assert.strictEqual(r.handler, 4) | ||
assert.strictEqual(r.params.name, 'john') | ||
{ | ||
handler: 2, | ||
params: {} | ||
} | ||
) | ||
r = router.find('/404') | ||
assert.strictEqual(r.handler, 5) | ||
assert.deepStrictEqual( | ||
router.find('/user/123'), | ||
{ | ||
handler: 3, | ||
params: { | ||
id: '123' | ||
} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/user/456/articles'), | ||
{ | ||
handler: 4, | ||
params: { | ||
id: '456', | ||
page: 'articles' | ||
} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/people/john'), | ||
{ | ||
handler: 5, | ||
params: { | ||
name: 'john' | ||
} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/404'), | ||
{ | ||
handler: 6, | ||
params: {} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/2019-11'), | ||
{ | ||
handler: 7, | ||
params: { | ||
year: '2019', | ||
month: '11' | ||
} | ||
} | ||
) | ||
``` | ||
@@ -44,0 +99,0 @@ |
@@ -6,26 +6,81 @@ const assert = require('assert') | ||
['/foo', 1], | ||
['/user/:id', 2], | ||
['/user/:id/:page', 3], | ||
['/people/:name(\\w+)', 4], | ||
['(.*)', 5] | ||
['/foo/bar', 2], | ||
['/user/:id', 3], | ||
['/user/:id/:page', 4], | ||
['/people/:name(\\w+)', 5], | ||
['(.*)', 6], | ||
['/:year(\\d+)-:month(\\d+)', 7] | ||
) | ||
let r | ||
r = router.find('/foo') | ||
assert.strictEqual(r.handler, 1) | ||
assert.deepStrictEqual( | ||
router.find('/foo'), | ||
r = router.find('/user/123') | ||
assert.strictEqual(r.handler, 2) | ||
assert.strictEqual(r.params.id, '123') | ||
{ | ||
handler: 1, | ||
params: {} | ||
} | ||
) | ||
r = router.find('/user/456/articles') | ||
assert.strictEqual(r.handler, 3) | ||
assert.strictEqual(r.params.id, '456') | ||
assert.strictEqual(r.params.page, 'articles') | ||
assert.deepStrictEqual( | ||
router.find('/foo/bar'), | ||
r = router.find('/people/john') | ||
assert.strictEqual(r.handler, 4) | ||
assert.strictEqual(r.params.name, 'john') | ||
{ | ||
handler: 2, | ||
params: {} | ||
} | ||
) | ||
r = router.find('/404') | ||
assert.strictEqual(r.handler, 5) | ||
assert.deepStrictEqual( | ||
router.find('/user/123'), | ||
{ | ||
handler: 3, | ||
params: { | ||
id: '123' | ||
} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/user/456/articles'), | ||
{ | ||
handler: 4, | ||
params: { | ||
id: '456', | ||
page: 'articles' | ||
} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/people/john'), | ||
{ | ||
handler: 5, | ||
params: { | ||
name: 'john' | ||
} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/404'), | ||
{ | ||
handler: 6, | ||
params: {} | ||
} | ||
) | ||
assert.deepStrictEqual( | ||
router.find('/2019-11'), | ||
{ | ||
handler: 7, | ||
params: { | ||
year: '2019', | ||
month: '11' | ||
} | ||
} | ||
) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15945
434
0
195