itty-router 2.5.3 → 2.6.0

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/README.md CHANGED
@@ -505,42 +505,6 @@ router.puppy('/', request => {}) // Strongly typed
505
505
  1. Submit PR with a detailed description of what you're doing
506
506
  1. I'll add you to the credits! :)
507
507
 
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
- ```js
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
- }
537
- }
538
- }
539
- }
540
- }
541
- }
542
- ```
543
-
544
508
  ## Special Thanks
545
509
  This repo goes out to my past and present colleagues at Arundo - who have brought me such inspiration, fun,
546
510
  and drive over the last couple years. In particular, the absurd brevity of this code is thanks to a
@@ -0,0 +1 @@
1
+ export default{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,13 +1,21 @@
1
1
  {
2
2
  "name": "itty-router",
3
- "version": "2.5.3",
3
+ "version": "2.6.0",
4
4
  "description": "Tiny, zero-dependency router with route param and query parsing - built for Cloudflare Workers, but works everywhere!",
5
- "main": "./dist/itty-router.min.js",
6
- "types": "./dist/itty-router.d.ts",
5
+ "sourceType": "module",
7
6
  "files": [
8
7
  "dist/itty-router.min.js",
8
+ "dist/itty-router.min.mjs",
9
9
  "dist/itty-router.d.ts"
10
10
  ],
11
+ "main": "./dist/itty-router.min.js",
12
+ "exports": {
13
+ ".": {
14
+ "require": "./dist/itty-router.min.js",
15
+ "import": "./dist/itty-router.min.mjs"
16
+ }
17
+ },
18
+ "types": "./dist/itty-router.d.ts",
11
19
  "keywords": [
12
20
  "router",
13
21
  "cloudflare",
@@ -47,7 +55,11 @@
47
55
  "coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
48
56
  "prerelease": "yarn verify",
49
57
  "prebuild": "rimraf dist && mkdir dist && node prebuild.js && cp src/itty-router.d.ts dist",
50
- "build": "uglifyjs dist/itty-router.js -c -m --toplevel > dist/itty-router.min.js",
58
+ "build": "yarn uglify",
59
+ "uglify": "yarn uglify:cjs && yarn uglify:esm",
60
+ "uglify:esm": "uglifyjs dist/itty-router.mjs -c -m --toplevel > dist/itty-router.min.mjs",
61
+ "uglify:cjs": "uglifyjs src/itty-router.js -c -m --toplevel > dist/itty-router.min.js",
62
+ "build:esm": "esbuild src/itty-router.js --format=esm --outfile=./dist/itty-router.mjs",
51
63
  "postbuild": "node check-size.js",
52
64
  "release": "release --tag --push"
53
65
  },
@@ -63,8 +75,8 @@
63
75
  "homepage": "https://itty-router.dev",
64
76
  "devDependencies": {
65
77
  "@vitejs/plugin-vue": "^2.2.4",
66
- "@vue/compiler-sfc": "^3.2.31",
67
78
  "coveralls": "^3.1.1",
79
+ "esbuild": "^0.14.27",
68
80
  "eslint": "^8.11.0",
69
81
  "eslint-plugin-jest": "^26.1.2",
70
82
  "fs-extra": "^10.0.1",
@@ -74,6 +86,7 @@
74
86
  "rimraf": "^3.0.2",
75
87
  "uglify-js": "^3.15.3",
76
88
  "vite": "^2.8.6",
89
+ "vue": "^3.2.31",
77
90
  "yarn": "^1.22.18",
78
91
  "yarn-release": "^1.10.3"
79
92
  }