itty-router 4.0.7 → 4.0.8

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/CONTRIBUTING.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  The [Open Source Guides](https://opensource.guide/) website has a collection of resources for individuals, communities, and companies. These resources help people who want to learn how to run and contribute to open source projects. Contributors and people new to open source alike will find the following guides especially useful:
4
4
 
5
- * [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
6
- * [Building Welcoming Communities](https://opensource.guide/building-community/)
5
+ - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
6
+ - [Building Welcoming Communities](https://opensource.guide/building-community/)
7
7
 
8
8
  ## Bugs
9
9
 
package/README.md CHANGED
@@ -8,7 +8,6 @@
8
8
  <h2 align="center"><a href="https://itty.dev/itty-router">v4.x Documentation @ itty.dev</a>
9
9
  <br /></h2>
10
10
 
11
-
12
11
  <p align="center">
13
12
  <a href="https://npmjs.com/package/itty-router" target="_blank">
14
13
  <img src="https://img.shields.io/npm/v/itty-router.svg?style=flat-square" alt="npm version" />
@@ -50,28 +49,29 @@
50
49
 
51
50
  ---
52
51
 
53
- Itty aims to be the world's smallest (~440 bytes), feature-rich JavaScript router, enabling beautiful API code with a near-zero bundlesize. Designed originally for [Cloudflare Workers](https://itty.dev/itty-router/runtimes#Cloudflare%20Workers), itty can be used in browsers, Service Workers, edge functions, or standalone runtimes like [Node](https://itty.dev/itty-router/runtimes#Node), [Bun](https://itty.dev/itty-router/runtimes#Bun), etc.!
52
+ Itty aims to be the world's smallest (~440 bytes), feature-rich JavaScript router, enabling beautiful API code with a near-zero bundlesize. Designed originally for [Cloudflare Workers](https://itty.dev/itty-router/runtimes#Cloudflare%20Workers), itty can be used in browsers, Service Workers, edge functions, or standalone runtimes like [Node](https://itty.dev/itty-router/runtimes#Node), [Bun](https://itty.dev/itty-router/runtimes#Bun), etc.!
54
53
 
55
54
  ## Features:
56
- - Absurdly tiny. The Router itself is ~440 bytes gzipped, and the **entire** library is under 1.5k!
57
- - Absurdly easy to use. We believe route code should be self-evident, obvious, and read more like poetry than code.
55
+
56
+ - Absurdly tiny. The Router itself is ~440 bytes gzipped, and the **entire** library is under 1.5k!
57
+ - Absurdly easy to use. We believe route code should be self-evident, obvious, and read more like poetry than code.
58
58
  - Absurdly agnostic. We leave **you** with full control over response types, matching order, upstream/downstream effects, etc.
59
59
  - Works [anywhere, in any environment](https://itty.dev/itty-router/runtimes).
60
60
  - [Fully typed/TypeScript support](https://itty.dev/itty-router/typescript), including hinting.
61
- - Parses [route params](https://itty.dev/itty-router/route-patterns#params),
61
+ - Parses [route params](https://itty.dev/itty-router/route-patterns#params),
62
62
  [optional params](https://itty.dev/itty-router/route-patterns#optional),
63
- [wildcards](https://itty.dev/itty-router/route-patterns#wildcards),
63
+ [wildcards](https://itty.dev/itty-router/route-patterns#wildcards),
64
64
  [greedy params](https://itty.dev/itty-router/route-patterns#greedy),
65
65
  and [file formats](https://itty.dev/itty-router/route-patterns#file-formats).
66
66
  - Automatic [query parsing](https://itty.dev/itty-router/route-patterns#query).
67
67
  - Easy [error handling](https://itty.dev/itty-router/errors), including throwing errors with HTTP status codes!
68
- - Easy [Response](https://itty.dev/itty-router/responses) creation, with helpers for major formats (e.g.
69
- [json](https://itty.dev/itty-router/api#json),
70
- [html](https://itty.dev/itty-router/api#html),
71
- [png](https://itty.dev/itty-router/api#png),
68
+ - Easy [Response](https://itty.dev/itty-router/responses) creation, with helpers for major formats (e.g.
69
+ [json](https://itty.dev/itty-router/api#json),
70
+ [html](https://itty.dev/itty-router/api#html),
71
+ [png](https://itty.dev/itty-router/api#png),
72
72
  [jpeg](https://itty.dev/itty-router/api#jpeg), etc.)
73
73
  - Deep APIs via [router nesting](https://itty.dev/itty-router/nesting).
74
- - Full [middleware](https://itty.dev/itty-router/middleware) support. Includes the following by default:
74
+ - Full [middleware](https://itty.dev/itty-router/middleware) support. Includes the following by default:
75
75
  - [withParams](https://itty.dev/itty-router/api#withParams) - access the params directly off the `Request` (instead of `request.params`).
76
76
  - [withCookies](https://itty.dev/itty-router/api#withCookies) - access cookies in a convenient Object format.
77
77
  - [withContent](https://itty.dev/itty-router/api#withContent) - auto-parse Request bodies as `request.content`.
@@ -79,35 +79,39 @@ Itty aims to be the world's smallest (~440 bytes), feature-rich JavaScript route
79
79
  - Fully readable regex... yeah right! 😆
80
80
 
81
81
  ## [Full Documentation](https://itty.dev/itty-router)
82
+
82
83
  Complete documentation/API is available at [itty.dev](https://itty.dev/itty-router), or join our [Discord](https://discord.com/channels/832353585802903572) channel to chat with community members for quick help!
83
84
 
84
85
  ## Installation
86
+
85
87
  ```
86
88
  npm install itty-router
87
89
  ```
88
90
 
89
91
  ## Example
92
+
90
93
  ```js
91
- import {
92
- error, // creates error responses
93
- json, // creates JSON responses
94
- Router, // the ~440 byte router itself
95
- withParams, // middleware: puts params directly on the Request
94
+ import {
95
+ error, // creates error responses
96
+ json, // creates JSON responses
97
+ Router, // the ~440 byte router itself
98
+ withParams, // middleware: puts params directly on the Request
96
99
  } from 'itty-router'
97
100
  import { todos } from './external/todos'
98
101
 
99
102
  // create a new Router
100
- const router = Router()
103
+ const router = Router()
101
104
 
102
105
  router
103
106
  // add some middleware upstream on all routes
104
- .all('*', withParams)
107
+ .all('*', withParams)
105
108
 
106
109
  // GET list of todos
107
110
  .get('/todos', () => todos)
108
111
 
109
112
  // GET single todo, by ID
110
- .get('/todos/:id',
113
+ .get(
114
+ '/todos/:id',
111
115
  ({ id }) => todos.getById(id) || error(404, 'That todo was not found')
112
116
  )
113
117
 
@@ -116,19 +120,22 @@ router
116
120
 
117
121
  // Example: Cloudflare Worker module syntax
118
122
  export default {
119
- fetch: (request, ...args) => router
120
- .handle(request, ...args)
121
- .then(json) // send as JSON
122
- .catch(error) // catch errors
123
+ fetch: (request, ...args) =>
124
+ router
125
+ .handle(request, ...args)
126
+ .then(json) // send as JSON
127
+ .catch(error), // catch errors
123
128
  }
124
129
  ```
125
130
 
126
131
  ## Join the Discussion!
132
+
127
133
  Have a question? Suggestion? Complaint? Want to send a gift basket?
128
134
 
129
135
  Join us on [Discord](https://discord.com/channels/832353585802903572)!
130
136
 
131
137
  ## Testing and Contributing
138
+
132
139
  1. Fork repo
133
140
  1. Install dev dependencies via `yarn`
134
141
  1. Start test runner/dev mode `yarn dev`
@@ -138,21 +145,29 @@ Join us on [Discord](https://discord.com/channels/832353585802903572)!
138
145
  1. I'll add you to the credits! :)
139
146
 
140
147
  ## Special Thanks: Contributors
141
- 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
148
+
149
+ 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
142
150
 
143
151
  #### Core Concepts
152
+
144
153
  - [@mvasigh](https://github.com/mvasigh) - proxy hack wizard behind itty, coding partner in crime, maker of the entire doc site, etc, etc.
145
154
  - [@hunterloftis](https://github.com/hunterloftis) - router.handle() method now accepts extra arguments and passed them to route functions
146
155
  - [@SupremeTechnopriest](https://github.com/SupremeTechnopriest) - improved TypeScript support and documentation! :D
156
+
147
157
  #### Code Golfing
158
+
148
159
  - [@taralx](https://github.com/taralx) - router internal code-golfing refactor for performance and character savings
149
160
  - [@DrLoopFall](https://github.com/DrLoopFall) - v4.x re-minification
161
+
150
162
  #### Fixes & Build
163
+
151
164
  - [@taralx](https://github.com/taralx) - QOL fixes for contributing (dev dep fix and test file consistency) <3
152
- - [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
165
+ - [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
153
166
  - [@roojay520](https://github.com/roojay520) - TS interface fixes
154
167
  - [@jahands](https://github.com/jahands) - v4.x TS fixes
168
+
155
169
  #### Documentation
170
+
156
171
  - [@arunsathiya](https://github.com/arunsathiya),
157
172
  [@poacher2k](https://github.com/poacher2k),
158
173
  [@ddarkr](https://github.com/ddarkr),
package/Router.d.ts CHANGED
@@ -28,7 +28,7 @@ export type RouteHandler<I = IRequest, A extends any[] = any[]> = {
28
28
  export type RouteEntry = [string, RegExp, RouteHandler[], string];
29
29
  export type Route = <RequestType = IRequest, Args extends any[] = any[], RT = RouterType>(path: string, ...handlers: RouteHandler<RequestType, Args>[]) => RT;
30
30
  export type UniversalRoute<RequestType = IRequest, Args extends any[] = any[]> = (path: string, ...handlers: RouteHandler<RequestType, Args>[]) => RouterType<UniversalRoute<RequestType, Args>, Args>;
31
- type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
31
+ type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
32
32
  export type CustomRoutes<R = Route> = {
33
33
  [key: string]: R;
34
34
  };
package/cjs/Router.d.ts CHANGED
@@ -28,7 +28,7 @@ export type RouteHandler<I = IRequest, A extends any[] = any[]> = {
28
28
  export type RouteEntry = [string, RegExp, RouteHandler[], string];
29
29
  export type Route = <RequestType = IRequest, Args extends any[] = any[], RT = RouterType>(path: string, ...handlers: RouteHandler<RequestType, Args>[]) => RT;
30
30
  export type UniversalRoute<RequestType = IRequest, Args extends any[] = any[]> = (path: string, ...handlers: RouteHandler<RequestType, Args>[]) => RouterType<UniversalRoute<RequestType, Args>, Args>;
31
- type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
31
+ type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
32
32
  export type CustomRoutes<R = Route> = {
33
33
  [key: string]: R;
34
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itty-router",
3
- "version": "4.0.7",
3
+ "version": "4.0.8",
4
4
  "description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -19,14 +19,16 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "dev": "yarn test",
22
- "lint": "npx eslint src",
22
+ "lint": "yarn run eslint src",
23
+ "prettier": "prettier --write src test example",
24
+ "format": "yarn lint && yarn prettier",
23
25
  "test": "vitest --coverage --reporter verbose",
24
26
  "test:once": "vitest run",
25
27
  "coverage": "vitest run --coverage",
26
28
  "coveralls": "yarn coverage && cat ./coverage/lcov.info | coveralls",
27
29
  "verify": "echo 'verifying module...' && yarn build && yarn test:once",
28
30
  "prerelease": "yarn verify",
29
- "prebuild": "rimraf dist && mkdir dist && yarn coverage && yarn lint",
31
+ "prebuild": "rimraf dist && mkdir dist && yarn coverage && yarn format",
30
32
  "build": "rollup -c",
31
33
  "release": "release --tag --push --patch --src=dist",
32
34
  "runtime:bun": "bun example/bun.ts",
@@ -56,6 +58,7 @@
56
58
  "@whatwg-node/server": "^0.8.1",
57
59
  "coveralls": "^3.1.1",
58
60
  "eslint": "^8.41.0",
61
+ "eslint-config-prettier": "^8.8.0",
59
62
  "fetch-mock": "^9.11.0",
60
63
  "fs-extra": "^11.1.1",
61
64
  "globby": "^13.1.4",
@@ -65,6 +68,7 @@
65
68
  "itty-router": "^4.0.6",
66
69
  "jsdom": "^22.1.0",
67
70
  "npm-run-all": "^4.1.5",
71
+ "prettier": "^2.8.8",
68
72
  "rimraf": "^5.0.1",
69
73
  "rollup": "^3.23.0",
70
74
  "rollup-plugin-bundle-size": "^1.0.3",