itty-router
Advanced tools
Comparing version 1.2.15 to 1.3.0
## Changelog | ||
Until this library makes it to a production release of v1.x, **minor versions may contain breaking changes to the API**. After v1.x, semantic versioning will be honored, and breaking changes will only occur under the umbrella of a major version bump. | ||
- **v1.3.0** - adds support for multiple args to handle(request, ...args) method (@hunterloftis) | ||
- **v1.2.2** - fix: require verify/build pass before publishing and fixed README badges (should point to v1.x branch) | ||
@@ -5,0 +6,0 @@ - **v1.2.0** - feature: chainable route declarations (with test)... that didn't take long... |
const Router = (o = {}) => | ||
new Proxy(o, { | ||
get: (t, k, c) => k === 'handle' | ||
? async q => { | ||
? async (q, ...args) => { | ||
for ([p, hs] of t[(q.method || 'GET').toLowerCase()] || []) { | ||
@@ -11,3 +11,3 @@ if (m = (u = new URL(q.url)).pathname.match(p)) { | ||
for (h of hs) { | ||
if ((s = await h(q)) !== undefined) return s | ||
if ((s = await h(q, ...args)) !== undefined) return s | ||
} | ||
@@ -14,0 +14,0 @@ } |
@@ -1,1 +0,1 @@ | ||
const e=(e={})=>new Proxy(e,{get:(r,a,o)=>"handle"===a?async e=>{for([p,hs]of r[(e.method||"GET").toLowerCase()]||[])if(m=(u=new URL(e.url)).pathname.match(p))for(h of(e.params=m.groups,e.query=Object.fromEntries(u.searchParams.entries()),hs))if(void 0!==(s=await h(e)))return s}:(s,...t)=>(r[a]=r[a]||[]).push([`^${(e.base||"")+s.replace(/(\/?)\*/g,"($1.*)?").replace(/:([^\/\?]+)(\?)?/g,"$2(?<$1>[^/]+)$2")}/?$`,t])&&o});module.exports={Router:e}; | ||
const e=(e={})=>new Proxy(e,{get:(r,a,o)=>"handle"===a?async(e,...a)=>{for([p,hs]of r[(e.method||"GET").toLowerCase()]||[])if(m=(u=new URL(e.url)).pathname.match(p))for(h of(e.params=m.groups,e.query=Object.fromEntries(u.searchParams.entries()),hs))if(void 0!==(s=await h(e,...a)))return s}:(s,...t)=>(r[a]=r[a]||[]).push([`^${(e.base||"")+s.replace(/(\/?)\*/g,"($1.*)?").replace(/:([^\/\?]+)(\?)?/g,"$2(?<$1>[^/]+)$2")}/?$`,t])&&o});module.exports={Router:e}; |
{ | ||
"name": "itty-router", | ||
"version": "1.2.15", | ||
"version": "1.3.0", | ||
"description": "Tiny, zero-dependency router with route param and query parsing.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/itty-router.min.js", |
@@ -197,3 +197,3 @@ ![Logo][logo-image] | ||
get: (t, k, c) => k === 'handle' | ||
? async q => { | ||
? async (q, ...args) => { | ||
for ([p, hs] of t[(q.method || 'GET').toLowerCase()] || []) { | ||
@@ -205,3 +205,3 @@ if (m = (u = new URL(q.url)).pathname.match(p)) { | ||
for (h of hs) { | ||
if ((s = await h(q)) !== undefined) return s | ||
if ((s = await h(q, ...args)) !== undefined) return s | ||
} | ||
@@ -215,4 +215,4 @@ } | ||
.replace(/(\/?)\*/g, '($1.*)?') | ||
.replace(/(\/:([^\/\?]+)(\?)?)/g, '/$3(?<$2>[^/]+)$3') | ||
}$`, | ||
.replace(/:([^\/\?]+)(\?)?/g, '$2(?<$1>[^/]+)$2') | ||
}\/?$`, | ||
hs | ||
@@ -249,5 +249,6 @@ ]) && c | ||
#### Core, Concepts, and Codebase | ||
- [@hunterloftis](https://github.com/hunterloftis) - router.handle() method now accepts extra arguments and passed them to route functions | ||
- [@roojay520](https://github.com/roojay520) - TS interface fixes | ||
- [@mvasigh](https://github.com/mvasigh) - proxy hacks courtesy of this chap | ||
- [@roojay520](https://github.com/roojay520) - TS interface fixes | ||
#### Documentation Fixes | ||
- [@arunsathiya](https://github.com/arunsathiya) |
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
16299
251