itty-router
Advanced tools
Comparing version 2.0.1 to 2.0.2
const Router = (o = {}) => | ||
new Proxy(o, { | ||
get: (t, k, c) => k === 'handle' | ||
? async (r, ...args) => { | ||
? async (r, ...a) => { | ||
for ([p, hs] of t.r.filter(r => r[0] === r.method || 'ALL')) { | ||
@@ -11,3 +11,3 @@ if (m = (u = new URL(r.url)).pathname.match(p)) { | ||
for (h of hs) { | ||
if ((s = await h(r, ...args)) !== undefined) return s | ||
if ((s = await h(r, ...a)) !== undefined) return s | ||
} | ||
@@ -14,0 +14,0 @@ } |
{ | ||
"name": "itty-router", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Tiny, zero-dependency router with route param and query parsing.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/itty-router.min.js", |
@@ -14,3 +14,3 @@ ![Logo][logo-image] | ||
``` | ||
yarn add itty-router | ||
npm install itty-router | ||
``` | ||
@@ -45,3 +45,3 @@ | ||
# Features | ||
- [x] tiny (<450 bytes) with zero dependencies | ||
- [x] tiny (~450 bytes) with zero dependencies | ||
- [x] route params, with optionals (e.g. `/api/:foo/:id?.:format?`) | ||
@@ -181,4 +181,4 @@ - [x] bonus query parsing (e.g. `?page=3&foo-bar`) | ||
get: (t, k, c) => k === 'handle' | ||
? async (r, ...args) => { | ||
for ([, p, hs] of t.r.filter(r => r[0] === r.method || 'ALL')) { | ||
? async (r, ...a) => { | ||
for ([p, hs] of t.r.filter(r => r[0] === r.method || 'ALL')) { | ||
if (m = (u = new URL(r.url)).pathname.match(p)) { | ||
@@ -189,3 +189,3 @@ r.params = m.groups | ||
for (h of hs) { | ||
if ((s = await h(r, ...args)) !== undefined) return s | ||
if ((s = await h(r, ...a)) !== undefined) return s | ||
} | ||
@@ -197,3 +197,2 @@ } | ||
(t.r = t.r || []).push([ | ||
k.toUpperCase(), | ||
`^${(t.base || '')+p | ||
@@ -204,3 +203,4 @@ .replace(/(\/?)\*/g, '($1.*)?') | ||
}\/*$`, | ||
hs | ||
hs, | ||
k.toUpperCase(), | ||
]) && c | ||
@@ -207,0 +207,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
16643