itty-router 2.5.1 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,7 @@ Until this library makes it to a production release of v1.x, **minor versions ma
3
3
 
4
4
  [@SupremeTechnopriest)(https://github.com/SupremeTechnopriest) - improved TypeScript support and documentation! :D\
5
5
 
6
+ - **v2.5.2** - fixes issue with arrow functions in CommonJS named exports (rare issue)
6
7
  - **v2.5.1** - added context to Cloudflare ES module syntax example (credit [@jcapogna](https://github.com/jcapogna))
7
8
  - **v2.5.0** - improved TypeScript docs/types (thanks [@SupremeTechnopriest](https://github.com/SupremeTechnopriest)!)
8
9
  - **v2.4.9** - fixed the cursed "optional" file format capturing bug - RIP all the bytes lost
package/README.md CHANGED
@@ -301,7 +301,7 @@ export default {
301
301
  export default {
302
302
  fetch: (...args) => router
303
303
  .handle(...args)
304
- .then(response =>
304
+ .then(response =>
305
305
  // can modify response here before final return, e.g. CORS headers
306
306
 
307
307
  return response
@@ -452,7 +452,7 @@ const router = Router<Request, IMethods>() // Valid
452
452
  const router = Router<void, IMethods>() // Valid
453
453
  ```
454
454
 
455
- The router will also accept any string as a method, not just those provided on the `TMethods` type.
455
+ The router will also accept any string as a method, not just those provided on the `TMethods` type.
456
456
 
457
457
  ```ts
458
458
  import { Router, Route } from 'itty-router'
@@ -507,36 +507,38 @@ router.puppy('/', request => {}) // Strongly typed
507
507
 
508
508
  ### The Entire Code (for more legibility, [see src on GitHub](https://github.com/kwhitley/itty-router/blob/v2.x/src/itty-router.js))
509
509
  ```js
510
- const Router = ({ base = '', routes = [] } = {}) => ({
511
- __proto__: new Proxy({}, {
512
- get: (t, k, c) => (p, ...H) =>
513
- routes.push([
514
- k.toUpperCase(),
515
- RegExp(`^${(base + p)
516
- .replace(/(\/?)\*/g, '($1.*)?')
517
- .replace(/\/$/, '')
518
- .replace(/:(\w+)(\?)?(\.)?/g, '$2(?<$1>[^/]+)$2$3')
519
- .replace(/\.(?=[\w(])/, '\\.')
520
- .replace(/\)\.\?\(([^\[]+)\[\^/g, '?)\\.?($1(?<=\\.)[^\\.')
521
- }/*$`),
522
- H,
523
- ]) && c
524
- }),
525
- routes,
526
- async handle (q, ...a) {
527
- let s, m,
528
- u = new URL(q.url)
529
- q.query = Object.fromEntries(u.searchParams)
530
- for (let [M, p, H] of routes) {
531
- if ((M === q.method || M === 'ALL') && (m = u.pathname.match(p))) {
532
- q.params = m.groups
533
- for (let h of H) {
534
- if ((s = await h(q.proxy || q, ...a)) !== undefined) return s
510
+ function Router({ base = '', routes = [] } = {}) {
511
+ return {
512
+ __proto__: new Proxy({}, {
513
+ get: (t, k, c) => (p, ...H) =>
514
+ routes.push([
515
+ k.toUpperCase(),
516
+ RegExp(`^${(base + p)
517
+ .replace(/(\/?)\*/g, '($1.*)?')
518
+ .replace(/\/$/, '')
519
+ .replace(/:(\w+)(\?)?(\.)?/g, '$2(?<$1>[^/]+)$2$3')
520
+ .replace(/\.(?=[\w(])/, '\\.')
521
+ .replace(/\)\.\?\(([^\[]+)\[\^/g, '?)\\.?($1(?<=\\.)[^\\.') // RIP all the bytes lost :'(
522
+ }/*$`),
523
+ H,
524
+ ]) && c
525
+ }),
526
+ routes,
527
+ async handle (q, ...a) {
528
+ let s, m,
529
+ u = new URL(q.url)
530
+ q.query = Object.fromEntries(u.searchParams)
531
+ for (let [M, p, H] of routes) {
532
+ if ((M === q.method || M === 'ALL') && (m = u.pathname.match(p))) {
533
+ q.params = m.groups
534
+ for (let h of H) {
535
+ if ((s = await h(q.proxy || q, ...a)) !== undefined) return s
536
+ }
535
537
  }
536
538
  }
537
539
  }
538
540
  }
539
- })
541
+ }
540
542
  ```
541
543
 
542
544
  ## Special Thanks
@@ -575,8 +577,8 @@ These folks are the real heroes, making open source the powerhouse that it is!
575
577
  - [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
576
578
  - [@roojay520](https://github.com/roojay520) - TS interface fixes
577
579
  #### Documentation
578
- - [@arunsathiya](https://github.com/arunsathiya),
579
- [@poacher2k](https://github.com/poacher2k),
580
- [@ddarkr](https://github.com/ddarkr),
580
+ - [@arunsathiya](https://github.com/arunsathiya),
581
+ [@poacher2k](https://github.com/poacher2k),
582
+ [@ddarkr](https://github.com/ddarkr),
581
583
  [@kclauson](https://github.com/kclauson),
582
584
  [@jcapogna](https://github.com/jcapogna)
@@ -1 +1 @@
1
- module.exports={Router:({base:p="",routes:u=[]}={})=>({__proto__:new Proxy({},{get:(e,a,o)=>(e,...r)=>u.push([a.toUpperCase(),RegExp(`^${(p+e).replace(/(\/?)\*/g,"($1.*)?").replace(/\/$/,"").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),r])&&o}),routes:u,async handle(e,...r){let a,o,p=new URL(e.url);e.query=Object.fromEntries(p.searchParams);for(var[t,s,c]of u)if((t===e.method||"ALL"===t)&&(o=p.pathname.match(s))){e.params=o.groups;for(var l of c)if(void 0!==(a=await l(e.proxy||e,...r)))return a}}})};
1
+ module.exports={Router:function({base:t="",routes:n=[]}={}){return{__proto__:new Proxy({},{get:(e,a,o)=>(e,...r)=>n.push([a.toUpperCase(),RegExp(`^${(t+e).replace(/(\/?)\*/g,"($1.*)?").replace(/\/$/,"").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),r])&&o}),routes:n,async handle(e,...r){let a,o,t=new URL(e.url);e.query=Object.fromEntries(t.searchParams);for(var[p,s,u]of n)if((p===e.method||"ALL"===p)&&(o=t.pathname.match(s))){e.params=o.groups;for(var c of u)if(void 0!==(a=await c(e.proxy||e,...r)))return a}}}}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itty-router",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "Tiny, zero-dependency router with route param and query parsing - built for Cloudflare Workers, but works everywhere!",
5
5
  "main": "./dist/itty-router.min.js",
6
6
  "types": "./dist/itty-router.d.ts",