itty-router
Advanced tools
Comparing version 0.5.1 to 0.5.2
{ | ||
"name": "itty-router", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Tiny, zero-dependency router with route param and query parsing.", | ||
@@ -5,0 +5,0 @@ "main": "src/Router.js", |
@@ -17,3 +17,3 @@ const Router = () => new Proxy({}, { | ||
: (path, handler) => | ||
(obj[prop] = obj[prop] || []).push([path.replace(/(\/:([^\/\?]+)(\?)?)/gi, '/$3(?<$2>[^\/]+)$3'), handler]) && obj | ||
(obj[prop] = obj[prop] || []).push([`^${path.replace(/(\/:([^\/\?]+)(\?)?)/gi, '/$3(?<$2>[^\/]+)$3')}$`, handler]) && obj | ||
}) | ||
@@ -20,0 +20,0 @@ |
@@ -9,2 +9,3 @@ const { Router } = require('./Router') | ||
let routes = [ | ||
{ path: '/', callback: jest.fn(extract), method: 'get' }, | ||
{ path: '/foo/first', callback: jest.fn(extract), method: 'get' }, | ||
@@ -36,2 +37,10 @@ { path: '/foo/:id', callback: jest.fn(extract), method: 'get' }, | ||
it('requires exact route match', () => { | ||
const route = routes.find(r => r.path === '/') | ||
router.handle(buildRequest({ path: '/foo' })) | ||
expect(route.callback).not.toHaveBeenCalled() | ||
}) | ||
it('match earliest routes that match', () => { | ||
@@ -38,0 +47,0 @@ const route = routes.find(r => r.path === '/foo/first') |
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
9111
80