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 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][logo-image]][itty-homepage]
2
-
3
- [![npm package][npm-image]][npm-url]
4
- [![minified + gzipped size][gzip-image]][gzip-url]
5
- ![Build Status](https://github.com/kwhitley/itty-router/actions/workflows/verify.yml/badge.svg)
6
- [![Coverage Status][coveralls-image]][coveralls-url]
7
- [![Open Issues][issues-image]][issues-url]
8
- <a href="https://npmjs.com/package/itty-router" target="\_parent">
9
- <img alt="" src="https://img.shields.io/npm/dm/itty-router.svg" />
10
- </a>
11
- [![Discord][discord-image]][discord-url]
12
- <a href="https://github.com/kwhitley/itty-router" target="\_parent">
13
- <img alt="" src="https://img.shields.io/github/stars/kwhitley/itty-router.svg?style=social&label=Star" />
14
- </a>
15
- <a href="https://twitter.com/kevinrwhitley" target="\_parent">
16
- <img alt="" src="https://img.shields.io/twitter/follow/kevinrwhitley.svg?style=social&label=Follow" />
17
- </a>
18
- <!--<a href="https://github.com/kwhitley/itty-router/discussions">
19
- <img alt="Join the discussion on Github" src="https://img.shields.io/badge/Github%20Discussions%20%26%20Support-Chat%20now!-blue" />
20
- </a>-->
1
+ # [![Itty Router](https://user-images.githubusercontent.com/865416/146679767-16be95b4-5dd7-4bcf-aed7-b8aa8c828f48.png)](https://itty-router.dev)
2
+
3
+ [![Version](https://img.shields.io/npm/v/itty-router.svg?style=flat-square)](https://npmjs.com/package/itty-router)
4
+ [![Bundle Size](https://img.shields.io/bundlephobia/minzip/itty-router?style=flat-square)](https://bundlephobia.com/result?p=itty-router)
5
+ ![Build Status](https://img.shields.io/github/workflow/status/kwhitley/itty-router/build?style=flat-square)
6
+ [![Coverage Status](https://img.shields.io/coveralls/github/kwhitley/itty-router/v2.x?style=flat-square)](https://coveralls.io/github/kwhitley/itty-router?branch=v2.x)
7
+ [![NPM Weekly Downloads](https://img.shields.io/npm/dw/itty-router?style=flat-square)](https://npmjs.com/package/itty-router)
8
+ [![Open Issues](https://img.shields.io/github/issues/kwhitley/itty-router?style=flat-square)](https://github.com/kwhitley/itty-router/issues)
9
+
10
+ [![Discord](https://img.shields.io/discord/832353585802903572?style=flat-square)](https://discord.com/channels/832353585802903572)
11
+ [![GitHub Repo stars](https://img.shields.io/github/stars/kwhitley/itty-router?style=social)](https://github.com/kwhitley/itty-router)
12
+ [![Twitter](https://img.shields.io/twitter/follow/kevinrwhitley.svg?style=social&label=Follow)](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) - (EXPERIMENTAL/alpha) creates a more direct object-like API for interacting with [Cloudflare Durable Objects](https://developers.cloudflare.com/workers/learning/using-durable-objects).
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-writted regex.
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
 
@@ -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(/\/$/,"").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}}}}};
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}}}}};
@@ -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(/\/$/,"").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};
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.1",
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
- "import": "./dist/itty-router.min.mjs"
17
+ "default": "./dist/itty-router.min.mjs"
16
18
  }
17
19
  },
18
20
  "types": "./dist/itty-router.d.ts",