Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/egoist/router
A router that works in Node.js, browser and Deno.
https://github.com/egoist/router
Last synced: 22 days ago
JSON representation
A router that works in Node.js, browser and Deno.
- Host: GitHub
- URL: https://github.com/egoist/router
- Owner: egoist
- License: mit
- Created: 2021-03-13T14:59:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-25T14:00:48.000Z (almost 3 years ago)
- Last Synced: 2024-10-04T11:53:56.330Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 122 KB
- Stars: 66
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - router
README
# @egoist/router
An Express-like router that works in Node.js, browser and Deno.
## Install
For Node.js:
```bash
npm i @egoist/router
``````ts
import { Router } from '@egoist/router'
```For Deno:
```ts
import { Router } from 'https://unpkg.com/@egoist/router/mod.js'
```## Usage
```ts
const router = new Router()router.get('/user/:user', (params) => {
console.log(params.user)
})router.get('/', () => {
// do something
})const matches = router.find('GET', '/user/egoist')
for (const m of matches) {
m.handler(m.params)
}
// prints: 'egoist'
```## Supported route pattern
All patterns that [Vue Router](https://next.router.vuejs.org/guide/essentials/route-matching-syntax.html) supports:
- `/user/:user`: Parameter
- `/:orderId(\\d+)`: Custom regexp
- `/:chapters+`: Repeatable params
- Consult the Vue Router docs for more..## License
MIT © [EGOIST](https://github.com/sponsors/egoist)