itty-router 2.6.1 → 2.6.3
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 +1 -0
- package/README.md +15 -39
- package/dist/itty-router.min.js +1 -1
- package/dist/itty-router.min.mjs +1 -1
- package/package.json +4 -2
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.6.2** - fixes issue with using base path of "/" with route definitions starting with "/" (creating double slash)
|
|
6
7
|
- **v2.6.1** - fixes named export in ESM/mjs export
|
|
7
8
|
- **v2.6.0** - package now is hybrid export, supporting both ESM (.mjs) and CJS (.js) minified versions
|
|
8
9
|
- **v2.5.3** - corrects type for router.handle to return Promise<any>
|
package/README.md
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
# [![Itty Router]
|
|
2
|
-
|
|
3
|
-
[](https://itty-router.dev)
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/itty-router)
|
|
4
|
+
[](https://bundlephobia.com/result?p=itty-router)
|
|
5
|
+

|
|
6
|
+
[](https://coveralls.io/github/kwhitley/itty-router?branch=v2.x)
|
|
7
|
+
[](https://npmjs.com/package/itty-router)
|
|
8
|
+
[](https://github.com/kwhitley/itty-router/issues)
|
|
9
|
+
|
|
10
|
+
[](https://discord.com/channels/832353585802903572)
|
|
11
|
+
[](https://github.com/kwhitley/itty-router)
|
|
12
|
+
[](https://www.twitter.com/kevinrwhitley)
|
|
21
13
|
|
|
22
14
|
Tiny, zero-dependency router with route param and query parsing - built for [Cloudflare Workers](https://developers.cloudflare.com/workers/), but works everywhere!
|
|
23
15
|
|
|
24
16
|
### Addons & Related Libraries
|
|
25
17
|
1. [itty-router-extras](https://www.npmjs.com/package/itty-router-extras) - adds quality-of-life improvements and utility functions for simplifying request/response code (e.g. middleware, cookies, body parsing, json handling, errors, and an itty version with automatic exception handling)!
|
|
26
|
-
2. [itty-durable](https://github.com/kwhitley/itty-durable) -
|
|
18
|
+
2. [itty-durable](https://github.com/kwhitley/itty-durable) - creates a more direct object-like API for interacting with [Cloudflare Durable Objects](https://developers.cloudflare.com/workers/learning/using-durable-objects).
|
|
27
19
|
|
|
28
20
|
## Features
|
|
29
21
|
- [x] Tiny ([~500 bytes](https://bundlephobia.com/package/itty-router) compressed), with zero dependencies.
|
|
@@ -196,7 +188,7 @@ GET /todos/jane?limit=2&page=1
|
|
|
196
188
|
### Nested Routers with 404 handling
|
|
197
189
|
```js
|
|
198
190
|
// lets save a missing handler
|
|
199
|
-
const missingHandler = new Response('Not found.', { status: 404 })
|
|
191
|
+
const missingHandler = () => new Response('Not found.', { status: 404 })
|
|
200
192
|
|
|
201
193
|
// create a parent router
|
|
202
194
|
const parentRouter = Router({ base: '/api' })
|
|
@@ -343,7 +335,7 @@ router
|
|
|
343
335
|
```
|
|
344
336
|
|
|
345
337
|
### Manual Routes
|
|
346
|
-
Thanks to a pretty sick refactor by [@taralx](https://github.com/taralx), we've added the ability to fully preload or push manual routes with hand-
|
|
338
|
+
Thanks to a pretty sick refactor by [@taralx](https://github.com/taralx), we've added the ability to fully preload or push manual routes with hand-written regex.
|
|
347
339
|
|
|
348
340
|
Why is this useful?
|
|
349
341
|
|
|
@@ -512,22 +504,6 @@ clever [abuse] of `Proxy`, courtesy of the brilliant [@mvasigh](https://github.c
|
|
|
512
504
|
This trick allows methods (e.g. "get", "post") to by defined dynamically by the router as they are requested,
|
|
513
505
|
**drastically** reducing boilerplate.
|
|
514
506
|
|
|
515
|
-
[twitter-image]:https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fitty-router
|
|
516
|
-
[logo-image]:https://user-images.githubusercontent.com/865416/146679767-16be95b4-5dd7-4bcf-aed7-b8aa8c828f48.png
|
|
517
|
-
[gzip-image]:https://img.shields.io/bundlephobia/minzip/itty-router
|
|
518
|
-
[gzip-url]:https://bundlephobia.com/result?p=itty-router
|
|
519
|
-
[issues-image]:https://img.shields.io/github/issues/kwhitley/itty-router
|
|
520
|
-
[issues-url]:https://github.com/kwhitley/itty-router/issues
|
|
521
|
-
[npm-image]:https://img.shields.io/npm/v/itty-router.svg
|
|
522
|
-
[npm-url]:http://npmjs.org/package/itty-router
|
|
523
|
-
[david-image]:https://david-dm.org/kwhitley/itty-router/status.svg
|
|
524
|
-
[david-url]:https://david-dm.org/kwhitley/itty-router
|
|
525
|
-
[coveralls-image]:https://coveralls.io/repos/github/kwhitley/itty-router/badge.svg?branch=v2.x
|
|
526
|
-
[coveralls-url]:https://coveralls.io/github/kwhitley/itty-router?branch=v2.x
|
|
527
|
-
[itty-homepage]:https://itty-router.dev
|
|
528
|
-
[discord-image]:https://img.shields.io/discord/832353585802903572
|
|
529
|
-
[discord-url]:https://discord.com/channels/832353585802903572
|
|
530
|
-
|
|
531
507
|
## Contributors
|
|
532
508
|
These folks are the real heroes, making open source the powerhouse that it is! Help out and get your name added to this list! <3
|
|
533
509
|
|
package/dist/itty-router.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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(
|
|
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/dist/itty-router.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e({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(
|
|
1
|
+
function e({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}}}}export default{Router:e};export{e as Router};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itty-router",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.3",
|
|
4
4
|
"description": "Tiny, zero-dependency router with route param and query parsing - built for Cloudflare Workers, but works everywhere!",
|
|
5
5
|
"sourceType": "module",
|
|
6
6
|
"files": [
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
"main": "./dist/itty-router.min.js",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
+
"types": "./dist/itty-router.d.ts",
|
|
15
|
+
"import": "./dist/itty-router.min.mjs",
|
|
14
16
|
"require": "./dist/itty-router.min.js",
|
|
15
|
-
"
|
|
17
|
+
"default": "./dist/itty-router.min.mjs"
|
|
16
18
|
}
|
|
17
19
|
},
|
|
18
20
|
"types": "./dist/itty-router.d.ts",
|