@pirxpilot/router 1.0.0 → 2.0.0
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 +57 -1
- package/index.js +244 -294
- package/lib/layer.js +39 -153
- package/lib/matcher.js +128 -0
- package/lib/route.js +59 -121
- package/package.json +7 -12
- package/HISTORY.md +0 -206
- package/SECURITY.md +0 -24
package/README.md
CHANGED
|
@@ -5,13 +5,69 @@
|
|
|
5
5
|
|
|
6
6
|
This is a simplified fork of [router] with some dependencies removed.
|
|
7
7
|
|
|
8
|
+
## Router Options
|
|
9
|
+
|
|
10
|
+
The router accepts an options object that can be used to customize its behavior:
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
const router = Router({
|
|
14
|
+
caseSensitive: false, // Enable case-sensitive routing
|
|
15
|
+
mergeParams: false, // Preserve req.params values from parent router
|
|
16
|
+
strict: false // Enable strict routing
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Available options:
|
|
21
|
+
|
|
22
|
+
- `caseSensitive` - Enable case-sensitive routing. By default routes are case-insensitive (e.g., "/foo" and "/FOO" are treated the same).
|
|
23
|
+
- `mergeParams` - Preserve the `req.params` values from the parent router. If the parent and the child have conflicting param names, the child's value take precedence.
|
|
24
|
+
- `strict` - Enable strict routing. By default "/foo" and "/foo/" are treated the same by the router.
|
|
25
|
+
|
|
26
|
+
## Pattern Matching with URLPattern API
|
|
27
|
+
|
|
28
|
+
This router uses the [URLPattern API] for path matching.
|
|
29
|
+
|
|
30
|
+
### Basic Pattern Examples
|
|
31
|
+
|
|
32
|
+
- Named parameters:
|
|
33
|
+
```js
|
|
34
|
+
router.get('/user/:id', (req, res) => { ... }) // matches /user/123, /user/abc
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- Optional parameters:
|
|
38
|
+
```js
|
|
39
|
+
router.get('/user/:name?', (req, res) => { ... }) // matches /user, /user/john
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Wildcard/Greedy matching:
|
|
43
|
+
```js
|
|
44
|
+
router.get('/files/:path*', (req, res) => { ... }) // matches /files, /files/docs, /files/docs/intro.pdf
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Advanced Pattern Examples
|
|
48
|
+
|
|
49
|
+
- Custom parameter patterns:
|
|
50
|
+
```js
|
|
51
|
+
router.get('/user/:id(\\d+)', (req, res) => { ... }) // matches /user/123 but not /user/abc
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- Multiple parameters:
|
|
55
|
+
```js
|
|
56
|
+
router.get('/api/:version/:resource', (req, res) => { ... }) // matches /api/v1/users
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- Group matching:
|
|
60
|
+
```js
|
|
61
|
+
router.get('/:category(books|movies)/:id', (req, res) => { ... }) // matches /books/123 or /movies/456
|
|
62
|
+
```
|
|
63
|
+
|
|
8
64
|
## License
|
|
9
65
|
|
|
10
66
|
[MIT](LICENSE)
|
|
11
67
|
|
|
12
68
|
[router]: https://github.com/pillarjs/router
|
|
69
|
+
[URLPattern API]: https://developer.mozilla.org/en-US/docs/Web/API/URLPattern
|
|
13
70
|
[npm-image]: https://img.shields.io/npm/v/@pirxpilot/router
|
|
14
71
|
[npm-url]: https://npmjs.org/package/@pirxpilot/router
|
|
15
72
|
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/router/check.yaml?branch=main
|
|
16
73
|
[build-url]: https://github.com/pirxpilot/router/actions/workflows/check.yaml
|
|
17
|
-
|