itty-router
Advanced tools
Comparing version 0.8.1 to 0.8.2
{ | ||
"name": "itty-router", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Tiny, zero-dependency router with route param and query parsing.", | ||
@@ -5,0 +5,0 @@ "main": "dist/itty-router.min.js", |
@@ -126,8 +126,8 @@ ![image](https://user-images.githubusercontent.com/865416/79531114-fa0d8200-8036-11ea-824d-70d84164b00a.png) | ||
const Router = () => new Proxy({}, { | ||
get: (obj, prop) => prop === 'handle' | ||
? (req) => { | ||
for ([route, handler] of obj[(req.method || 'GET').toLowerCase()] || []) { | ||
if (hit = (u = new URL(req.url)).pathname.match(route)) { | ||
return handler(Object.assign(req, { | ||
params: hit.groups, | ||
get: (o, k) => k === 'handle' | ||
? (c) => { | ||
for ([r, h] of o[(c.method || 'GET').toLowerCase()] || []) { | ||
if (m = (u = new URL(c.url)).pathname.match(r)) { | ||
return h(Object.assign(c, { | ||
params: m.groups, | ||
query: Object.fromEntries(u.searchParams.entries()) | ||
@@ -137,4 +137,4 @@ })) | ||
} | ||
} : (path, handler) => | ||
(obj[prop] = obj[prop] || []).push([`^${path.replace('*', '.*').replace(/(\/:([^\/\?]+)(\?)?)/gi, '/$3(?<$2>[^\/]+)$3')}$`, handler]) && obj | ||
} : (p, h) => | ||
(o[k] = o[k] || []).push([`^${p.replace('*', '.*').replace(/(\/:([^\/\?]+)(\?)?)/gi, '/$3(?<$2>[^\/]+)$3')}$`, h]) && o | ||
}) | ||
@@ -141,0 +141,0 @@ ``` |
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
9660