@bit-js/blitz
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "@bit-js/blitz", | ||
"main": "lib/index.js", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "devDependencies": { |
@@ -73,2 +73,31 @@ # Blitz | ||
### URL routers | ||
These are internals router built for path matching only. | ||
```ts | ||
import { internal } from '@bit-js/blitz'; | ||
// Blitz router with only path matching | ||
const router = new internal.Radix<number>(); | ||
// EdgeRouter with only path matching; | ||
const router = new internal.Edge<number>(); | ||
// Register routes | ||
router.put('/', 0); | ||
router.put('/:id', 1); | ||
router.put('/*', 2); | ||
// Merging routes | ||
router.merge(otherInternalRouter); | ||
// Get the matching function | ||
const f = router.buildMatcher({}, 3); | ||
f(ctx); | ||
``` | ||
The match context only has: | ||
`ctx.path`: The parsed pathname. | ||
`ctx.params`: The output parameters. | ||
### FS router | ||
@@ -111,2 +140,10 @@ A cross-runtime file system router API. | ||
#### Route style | ||
Route style is a function that accepts a relative path and returns the correct route pattern. | ||
```ts | ||
type Style = (path: string) => string | null; | ||
``` | ||
If the return result is null the path will be ignored. | ||
#### Default style | ||
@@ -113,0 +150,0 @@ - `basic`: NextJS route style (wildcard only supports `[...]` and wildcard parameter name is always `$`). |
31627
153