clear-router 2.0.6 → 2.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/README.md +27 -149
- package/dist/express/{router.cjs → index.cjs} +2 -3
- package/dist/express/{router.d.cts → index.d.cts} +1 -1
- package/dist/express/{router.d.mts → index.d.mts} +1 -1
- package/dist/express/{router.mjs → index.mjs} +1 -1
- package/dist/h3/{router.cjs → index.cjs} +2 -3
- package/dist/h3/{router.d.cts → index.d.cts} +2 -2
- package/dist/h3/{router.d.mts → index.d.mts} +2 -2
- package/dist/h3/{router.mjs → index.mjs} +1 -1
- package/dist/types/h3.d.mts +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -4,20 +4,32 @@ Laravel-style routing system for Express.js in JavaScript. Clean route definitio
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
npm install clear-router
|
|
7
|
+
```sh
|
|
8
|
+
npm install clear-router h3
|
|
9
|
+
|
|
10
|
+
# OR
|
|
11
|
+
|
|
12
|
+
npm install clear-router express
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
OR
|
|
12
16
|
|
|
13
17
|
```bash
|
|
14
|
-
pnpm add clear-router
|
|
18
|
+
pnpm add clear-router h3
|
|
19
|
+
|
|
20
|
+
# OR
|
|
21
|
+
|
|
22
|
+
pnpm add clear-router hexpress3
|
|
15
23
|
```
|
|
16
24
|
|
|
17
25
|
OR
|
|
18
26
|
|
|
19
27
|
```bash
|
|
20
|
-
yarn add clear-router
|
|
28
|
+
yarn add clear-router h3
|
|
29
|
+
|
|
30
|
+
# OR
|
|
31
|
+
|
|
32
|
+
yarn add clear-router express
|
|
21
33
|
```
|
|
22
34
|
|
|
23
35
|
## Features
|
|
@@ -32,155 +44,21 @@ yarn add clear-router
|
|
|
32
44
|
- Error handling delegated to Express
|
|
33
45
|
- Route inspection with allRoutes method
|
|
34
46
|
- Fully Express-compatible
|
|
47
|
+
- Fully H3-compatible
|
|
35
48
|
|
|
36
49
|
## Quick Start
|
|
37
50
|
|
|
38
|
-
###
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
const express = require('express');
|
|
42
|
-
const Routes = require('clear-router');
|
|
43
|
-
|
|
44
|
-
const app = express();
|
|
45
|
-
const router = express.Router();
|
|
46
|
-
|
|
47
|
-
Router.get('/hello', ({ res }) => {
|
|
48
|
-
res.send('Hello World');
|
|
49
|
-
});
|
|
51
|
+
### Express JS
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
app.use(router);
|
|
53
|
-
|
|
54
|
-
app.listen(3000);
|
|
55
|
-
```
|
|
53
|
+
See the [Express JS documentation](./docs/EXPRESS.md) for details.
|
|
56
54
|
|
|
57
|
-
###
|
|
55
|
+
### H3
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
import express from 'express';
|
|
61
|
-
import Router from 'clear-router';
|
|
62
|
-
|
|
63
|
-
const app = express();
|
|
64
|
-
const router = express.Router();
|
|
65
|
-
|
|
66
|
-
Router.get('/hello', ({ res }) => {
|
|
67
|
-
res.send('Hello World');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
await Router.apply(router);
|
|
71
|
-
app.use(router);
|
|
72
|
-
|
|
73
|
-
app.listen(3000);
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### TypeScript
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
import express from 'express';
|
|
80
|
-
import Router from 'clear-router';
|
|
81
|
-
|
|
82
|
-
const app = express();
|
|
83
|
-
const router = express.Router();
|
|
84
|
-
|
|
85
|
-
Router.get('/hello', ({ res }) => {
|
|
86
|
-
res.send('Hello World');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
await Router.apply(router);
|
|
90
|
-
app.use(router);
|
|
91
|
-
|
|
92
|
-
app.listen(3000);
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## Usage Examples
|
|
96
|
-
|
|
97
|
-
### Basic Route
|
|
98
|
-
|
|
99
|
-
```javascript
|
|
100
|
-
Router.get('/hello', ({ res }) => {
|
|
101
|
-
res.send('Hello World');
|
|
102
|
-
});
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### With Middleware
|
|
106
|
-
|
|
107
|
-
```javascript
|
|
108
|
-
const authMiddleware = (req, res, next) => {
|
|
109
|
-
// auth logic
|
|
110
|
-
next();
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
Router.post('/secure', ({ res }) => res.send('Protected'), [authMiddleware]);
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Controller Binding
|
|
117
|
-
|
|
118
|
-
```javascript
|
|
119
|
-
class UserController {
|
|
120
|
-
static index({ res }) {
|
|
121
|
-
res.send('User List');
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
Router.get('/users', [UserController, 'index']);
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Class-based handlers will auto-bind to static or instance methods.
|
|
129
|
-
|
|
130
|
-
### Grouped Routes
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
Router.group('/admin', () => {
|
|
134
|
-
Router.get('/dashboard', ({ res }) => res.send('Admin Panel'));
|
|
135
|
-
});
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
With middleware:
|
|
139
|
-
|
|
140
|
-
```javascript
|
|
141
|
-
Router.group(
|
|
142
|
-
'/secure',
|
|
143
|
-
() => {
|
|
144
|
-
Router.get('/data', ({ res }) => res.send('Secure Data'));
|
|
145
|
-
},
|
|
146
|
-
[authMiddleware],
|
|
147
|
-
);
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### Global Middleware Scope
|
|
151
|
-
|
|
152
|
-
```javascript
|
|
153
|
-
Router.middleware([authMiddleware], () => {
|
|
154
|
-
Router.get('/profile', ({ res }) => res.send('My Profile'));
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### Multiple HTTP Methods
|
|
159
|
-
|
|
160
|
-
```javascript
|
|
161
|
-
Router.add(['get', 'post'], '/handle', ({ req, res }) => {
|
|
162
|
-
res.send(`Method: ${req.method}`);
|
|
163
|
-
});
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### Inspecting Routes
|
|
167
|
-
|
|
168
|
-
```javascript
|
|
169
|
-
Router.get('/hello', ({ res }) => res.send('Hello'));
|
|
170
|
-
Router.post('/world', ({ res }) => res.send('World'));
|
|
171
|
-
|
|
172
|
-
const allRoutes = Router.allRoutes();
|
|
173
|
-
console.log(allRoutes);
|
|
174
|
-
// Output:
|
|
175
|
-
// [
|
|
176
|
-
// { methods: ['get'], path: '/hello', middlewareCount: 0, handlerType: 'function' },
|
|
177
|
-
// { methods: ['post'], path: '/world', middlewareCount: 0, handlerType: 'function' }
|
|
178
|
-
// ]
|
|
179
|
-
```
|
|
57
|
+
See the [H3 documentation](./docs/H3.md) for details.
|
|
180
58
|
|
|
181
59
|
## API Reference
|
|
182
60
|
|
|
183
|
-
See [API.md](API.md) for complete API documentation.
|
|
61
|
+
See [API.md](./docs/API.md) for complete API documentation.
|
|
184
62
|
|
|
185
63
|
## Error Handling
|
|
186
64
|
|
|
@@ -213,7 +91,7 @@ npm run test:esm # Test ESM
|
|
|
213
91
|
npm run test:ts # Test TypeScript
|
|
214
92
|
```
|
|
215
93
|
|
|
216
|
-
See [TESTING.md](TESTING.md) for detailed testing guide.
|
|
94
|
+
See [TESTING.md](./docs/TESTING.md) for detailed testing guide.
|
|
217
95
|
|
|
218
96
|
## Examples
|
|
219
97
|
|
|
@@ -232,16 +110,16 @@ See [CHANGELOG.md](CHANGELOG.md) for version history.
|
|
|
232
110
|
## Requirements
|
|
233
111
|
|
|
234
112
|
- Node.js >= 14.0.0
|
|
235
|
-
- Express >= 5.0.0
|
|
113
|
+
- Express >= 5.0.0 | H3 >= 2.0.1
|
|
236
114
|
|
|
237
115
|
## License
|
|
238
116
|
|
|
239
|
-
MIT License © 2026
|
|
117
|
+
MIT License © 2026 ToneFlix Technologies Limited
|
|
240
118
|
|
|
241
119
|
## Author
|
|
242
120
|
|
|
243
|
-
|
|
121
|
+
3m1n3nce <3m1n3nce@toneflix.net>
|
|
244
122
|
|
|
245
123
|
## Repository
|
|
246
124
|
|
|
247
|
-
https://github.com/
|
|
125
|
+
https://github.com/toneflix/clear-router
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
//#region src/express/router.ts
|
|
4
4
|
/**
|
|
@@ -248,5 +248,4 @@ var Router = class {
|
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
//#endregion
|
|
251
|
-
exports.Router = Router;
|
|
252
|
-
exports.default = Router;
|
|
251
|
+
exports.Router = Router;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
//#region src/h3/router.ts
|
|
4
4
|
/**
|
|
@@ -251,5 +251,4 @@ var Router = class {
|
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
//#endregion
|
|
254
|
-
exports.Router = Router;
|
|
255
|
-
exports.default = Router;
|
|
254
|
+
exports.Router = Router;
|
|
@@ -8,7 +8,7 @@ type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
|
8
8
|
/**
|
|
9
9
|
* HTTP context passed to route handlers
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
interface HttpContext extends H3Event {}
|
|
12
12
|
/**
|
|
13
13
|
* Route handler function type
|
|
14
14
|
*/
|
|
@@ -149,4 +149,4 @@ declare class Router {
|
|
|
149
149
|
static apply(app: H3): H3App;
|
|
150
150
|
}
|
|
151
151
|
//#endregion
|
|
152
|
-
export { Router
|
|
152
|
+
export { Router };
|
|
@@ -8,7 +8,7 @@ type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
|
8
8
|
/**
|
|
9
9
|
* HTTP context passed to route handlers
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
interface HttpContext extends H3Event {}
|
|
12
12
|
/**
|
|
13
13
|
* Route handler function type
|
|
14
14
|
*/
|
|
@@ -149,4 +149,4 @@ declare class Router {
|
|
|
149
149
|
static apply(app: H3): H3App;
|
|
150
150
|
}
|
|
151
151
|
//#endregion
|
|
152
|
-
export { Router
|
|
152
|
+
export { Router };
|
package/dist/types/h3.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-router",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Laravel-style routing system for Express.js and H3, with CommonJS, ESM, and TypeScript support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"h3",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"module": "dist/express/routes.mjs",
|
|
33
33
|
"types": "dist/express/routes.d.mts",
|
|
34
34
|
"exports": {
|
|
35
|
-
"./express
|
|
36
|
-
"import": "./dist/express/
|
|
37
|
-
"require": "./dist/express/
|
|
35
|
+
"./express": {
|
|
36
|
+
"import": "./dist/express/index.mjs",
|
|
37
|
+
"require": "./dist/express/index.cjs"
|
|
38
38
|
},
|
|
39
|
-
"./h3
|
|
40
|
-
"import": "./dist/h3/
|
|
41
|
-
"require": "./dist/h3/
|
|
39
|
+
"./h3": {
|
|
40
|
+
"import": "./dist/h3/index.mjs",
|
|
41
|
+
"require": "./dist/h3/index.cjs"
|
|
42
42
|
},
|
|
43
43
|
"./types/basic": "./dist/types/basic.mjs",
|
|
44
44
|
"./types/express": "./dist/types/express.mjs",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"node": ">=22.0.0"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
|
-
"test": "
|
|
80
|
+
"test": "pnpm test:esm && pnpm test:ts",
|
|
81
81
|
"test:esm": "vitest tests/esm.test.ts",
|
|
82
82
|
"test:ts": "vitest tests/typescript.test.ts",
|
|
83
83
|
"example": "tsx example/express/index.ts",
|