itty-router 2.6.1 → 2.6.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 +1 -0
- package/README.md +3 -3
- 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
|
@@ -23,7 +23,7 @@ Tiny, zero-dependency router with route param and query parsing - built for [Clo
|
|
|
23
23
|
|
|
24
24
|
### Addons & Related Libraries
|
|
25
25
|
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) -
|
|
26
|
+
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
27
|
|
|
28
28
|
## Features
|
|
29
29
|
- [x] Tiny ([~500 bytes](https://bundlephobia.com/package/itty-router) compressed), with zero dependencies.
|
|
@@ -196,7 +196,7 @@ GET /todos/jane?limit=2&page=1
|
|
|
196
196
|
### Nested Routers with 404 handling
|
|
197
197
|
```js
|
|
198
198
|
// lets save a missing handler
|
|
199
|
-
const missingHandler = new Response('Not found.', { status: 404 })
|
|
199
|
+
const missingHandler = () => new Response('Not found.', { status: 404 })
|
|
200
200
|
|
|
201
201
|
// create a parent router
|
|
202
202
|
const parentRouter = Router({ base: '/api' })
|
|
@@ -343,7 +343,7 @@ router
|
|
|
343
343
|
```
|
|
344
344
|
|
|
345
345
|
### 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-
|
|
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-written regex.
|
|
347
347
|
|
|
348
348
|
Why is this useful?
|
|
349
349
|
|
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.2",
|
|
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",
|