itty-router 2.4.5 → 2.4.9
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 +2 -0
- package/README.md +11 -10
- package/dist/itty-router.min.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
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.
|
|
3
3
|
|
|
4
|
+
- **v2.4.7** - fixed the cursed "optional" file format capturing bug - RIP all the bytes lost
|
|
5
|
+
- **v2.4.6** - fixed README issues
|
|
4
6
|
- **v2.4.1** - fixed type errors introduced with 2.4.0
|
|
5
7
|
- **v2.4.0** - HUGE internal code-golfing refactor thanks to [@taralx](https://github.com/taralx)! Super cool work on this!!!
|
|
6
8
|
- **v2.3.10** - fix: dots now properly escaped (e.g. /image.jpg should not match /imageXjpg)
|
package/README.md
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
It's an itty bitty router, designed for express-like routing within [Cloudflare Workers](https://developers.cloudflare.com/workers/) (or anywhere else). Like... it's super tiny ([~4xx bytes](https://bundlephobia.com/package/itty-router)), with zero dependencies. For reals.
|
|
23
23
|
|
|
24
24
|
### Addons & Related Libraries
|
|
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) - creates a more direct object-like API for interacting with [Cloudflare Durable Objects](https://developers.cloudflare.com/workers/learning/using-durable-objects).
|
|
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) - (EXPERIMENTAL/alpha) 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 ([~4xx bytes](https://bundlephobia.com/package/itty-router) compressed) with zero dependencies.
|
|
@@ -198,7 +198,7 @@ GET /todos/jane?limit=2&page=1
|
|
|
198
198
|
const missingHandler = new Response('Not found.', { status: 404 })
|
|
199
199
|
|
|
200
200
|
// create a parent router
|
|
201
|
-
const parentRouter = Router({ base: '/api' )
|
|
201
|
+
const parentRouter = Router({ base: '/api' })
|
|
202
202
|
|
|
203
203
|
// and a child router (with FULL base path defined, from root)
|
|
204
204
|
const todosRouter = Router({ base: '/api/todos' })
|
|
@@ -399,6 +399,7 @@ const Router = ({ base = '', routes = [] } = {}) => ({
|
|
|
399
399
|
.replace(/\/$/, '')
|
|
400
400
|
.replace(/:(\w+)(\?)?(\.)?/g, '$2(?<$1>[^/]+)$2$3')
|
|
401
401
|
.replace(/\.(?=[\w(])/, '\\.')
|
|
402
|
+
.replace(/\)\.\?\(([^\[]+)\[\^/g, '?)\\.?($1(?<=\\.)[^\\.')
|
|
402
403
|
}/*$`),
|
|
403
404
|
H,
|
|
404
405
|
]) && c
|
|
@@ -428,19 +429,19 @@ This trick allows methods (e.g. "get", "post") to by defined dynamically by the
|
|
|
428
429
|
**drastically** reducing boilerplate.
|
|
429
430
|
|
|
430
431
|
[twitter-image]:https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fitty-router
|
|
431
|
-
[logo-image]:https://user-images.githubusercontent.com/865416/
|
|
432
|
+
[logo-image]:https://user-images.githubusercontent.com/865416/146679767-16be95b4-5dd7-4bcf-aed7-b8aa8c828f48.png
|
|
432
433
|
[gzip-image]:https://img.shields.io/bundlephobia/minzip/itty-router
|
|
433
434
|
[gzip-url]:https://bundlephobia.com/result?p=itty-router
|
|
434
435
|
[issues-image]:https://img.shields.io/github/issues/kwhitley/itty-router
|
|
435
436
|
[issues-url]:https://github.com/kwhitley/itty-router/issues
|
|
436
437
|
[npm-image]:https://img.shields.io/npm/v/itty-router.svg
|
|
437
438
|
[npm-url]:http://npmjs.org/package/itty-router
|
|
438
|
-
[travis-image]:https://travis-ci.
|
|
439
|
+
[travis-image]:https://app.travis-ci.com/kwhitley/itty-router.svg?branch=v2.x
|
|
439
440
|
[travis-url]:https://travis-ci.org/kwhitley/itty-router
|
|
440
441
|
[david-image]:https://david-dm.org/kwhitley/itty-router/status.svg
|
|
441
442
|
[david-url]:https://david-dm.org/kwhitley/itty-router
|
|
442
|
-
[coveralls-image]:https://coveralls.io/repos/github/kwhitley/itty-router/badge.svg?branch=
|
|
443
|
-
[coveralls-url]:https://coveralls.io/github/kwhitley/itty-router?branch=
|
|
443
|
+
[coveralls-image]:https://coveralls.io/repos/github/kwhitley/itty-router/badge.svg?branch=v2.x
|
|
444
|
+
[coveralls-url]:https://coveralls.io/github/kwhitley/itty-router?branch=v2.x
|
|
444
445
|
[itty-homepage]:https://itty-router.dev
|
|
445
446
|
[discord-image]:https://img.shields.io/discord/832353585802903572
|
|
446
447
|
[discord-url]:https://discord.com/channels/832353585802903572
|
|
@@ -449,12 +450,12 @@ This trick allows methods (e.g. "get", "post") to by defined dynamically by the
|
|
|
449
450
|
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
|
|
450
451
|
|
|
451
452
|
#### Core, Concepts, and Codebase
|
|
453
|
+
- [@mvasigh](https://github.com/mvasigh) - proxy hack wizard behind itty, coding partner in crime, maker of the entire doc site, etc, etc.
|
|
452
454
|
- [@taralx](https://github.com/taralx) - router internal code-golfing refactor for performance and character savings
|
|
453
455
|
- [@hunterloftis](https://github.com/hunterloftis) - router.handle() method now accepts extra arguments and passed them to route functions
|
|
454
|
-
- [@mvasigh](https://github.com/mvasigh) - proxy hacks courtesy of this chap
|
|
455
456
|
#### Fixes
|
|
456
457
|
- [@taralx](https://github.com/taralx) - QOL fixes for contributing (dev dep fix and test file consistency) <3
|
|
457
458
|
- [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
|
|
458
459
|
- [@roojay520](https://github.com/roojay520) - TS interface fixes
|
|
459
|
-
|
|
460
|
-
- [@poacher2k](https://github.com/poacher2k)
|
|
460
|
+
#### Documentation
|
|
461
|
+
- [@arunsathiya](https://github.com/arunsathiya), [@poacher2k](https://github.com/poacher2k), [@ddarkr](https://github.com/ddarkr), [@kclauson](https://github.com/kclauson)
|
package/dist/itty-router.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports={Router:({base:
|
|
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}}})};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itty-router",
|
|
3
|
-
"version": "2.4.
|
|
4
|
-
"description": "Tiny, zero-dependency router with route param and query parsing -
|
|
3
|
+
"version": "2.4.9",
|
|
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",
|
|
7
7
|
"files": [
|