Comparing version
@@ -71,4 +71,4 @@ declare const NODE_TYPES: { | ||
interface RouteTable { | ||
static: Map<string, RadixNodeData>; | ||
wildcard: Map<string, RadixNodeData>; | ||
static: Map<string, RadixNodeData | null>; | ||
wildcard: Map<string, RadixNodeData | null>; | ||
dynamic: Map<string, RouteTable>; | ||
@@ -86,2 +86,2 @@ } | ||
export { MatchedRoute, MatcherExport, NODE_TYPE, NODE_TYPES, RadixNode, RadixNodeData, RadixRouter, RadixRouterContext, RadixRouterOptions, RouteMatcher, RouteTable, createMatcherFromExport, createRouter, exportMatcher, toRouteMatcher }; | ||
export { type MatchedRoute, type MatcherExport, type NODE_TYPE, NODE_TYPES, type RadixNode, type RadixNodeData, type RadixRouter, type RadixRouterContext, type RadixRouterOptions, type RouteMatcher, type RouteTable, createMatcherFromExport, createRouter, exportMatcher, toRouteMatcher }; |
{ | ||
"name": "radix3", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Lightweight and fast router for JavaScript based on Radix Tree", | ||
@@ -22,20 +22,2 @@ "repository": "unjs/radix3", | ||
], | ||
"devDependencies": { | ||
"0x": "^5.5.0", | ||
"@vitest/coverage-c8": "^0.30.1", | ||
"autocannon": "^7.10.0", | ||
"benchmark": "^2.1.4", | ||
"changelogen": "^0.5.3", | ||
"eslint": "^8.39.0", | ||
"eslint-config-unjs": "^0.1.0", | ||
"jiti": "^1.18.2", | ||
"listhen": "^1.0.4", | ||
"ohmyfetch": "^0.4.21", | ||
"prettier": "^2.8.8", | ||
"standard-version": "^9.5.0", | ||
"typescript": "^5.0.4", | ||
"unbuild": "^1.2.1", | ||
"vitest": "^0.30.1" | ||
}, | ||
"packageManager": "pnpm@7.32.2", | ||
"scripts": { | ||
@@ -51,4 +33,22 @@ "bench": "node ./benchmark/direct.mjs", | ||
"release": "pnpm test && pnpm build && changelogen --release && git push --follow-tags && pnpm publish", | ||
"test": "pnpm lint && vitest run" | ||
} | ||
"test": "pnpm lint && pnpm test:types && vitest run", | ||
"test:types": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"0x": "^5.7.0", | ||
"@vitest/coverage-v8": "^1.3.1", | ||
"autocannon": "^7.15.0", | ||
"benchmark": "^2.1.4", | ||
"changelogen": "^0.5.5", | ||
"eslint": "^8.57.0", | ||
"eslint-config-unjs": "^0.2.1", | ||
"jiti": "^1.21.0", | ||
"listhen": "^1.7.2", | ||
"prettier": "^3.2.5", | ||
"standard-version": "^9.5.0", | ||
"typescript": "^5.4.2", | ||
"unbuild": "^2.0.0", | ||
"vitest": "^1.3.1" | ||
}, | ||
"packageManager": "pnpm@8.15.4" | ||
} |
@@ -31,6 +31,6 @@ # 🌳 radix3 | ||
// ESM | ||
import { createRouter } from 'radix3' | ||
import { createRouter } from "radix3"; | ||
// CJS | ||
const { createRouter } = require('radix3') | ||
const { createRouter } = require("radix3"); | ||
``` | ||
@@ -41,8 +41,8 @@ | ||
```js | ||
const router = createRouter(/* options */) | ||
const router = createRouter(/* options */); | ||
router.insert('/path', { payload: 'this path' }) | ||
router.insert('/path/:name', { payload: 'named route' }) | ||
router.insert('/path/foo/**', { payload: 'wildcard route' }) | ||
router.insert('/path/foo/**:name', { payload: 'named wildcard route' }) | ||
router.insert("/path", { payload: "this path" }); | ||
router.insert("/path/:name", { payload: "named route" }); | ||
router.insert("/path/foo/**", { payload: "wildcard route" }); | ||
router.insert("/path/foo/**:name", { payload: "named wildcard route" }); | ||
``` | ||
@@ -53,12 +53,12 @@ | ||
```js | ||
router.lookup('/path') | ||
router.lookup("/path"); | ||
// { payload: 'this path' } | ||
router.lookup('/path/fooval') | ||
router.lookup("/path/fooval"); | ||
// { payload: 'named route', params: { name: 'fooval' } } | ||
router.lookup('/path/foo/bar/baz') | ||
router.lookup("/path/foo/bar/baz"); | ||
// { payload: 'wildcard route' } | ||
router.lookup('/') | ||
router.lookup("/"); | ||
// null (no route matched for/) | ||
@@ -91,5 +91,5 @@ ``` | ||
routes: { | ||
'/foo': {} | ||
} | ||
}) | ||
"/foo": {}, | ||
}, | ||
}); | ||
``` | ||
@@ -105,17 +105,17 @@ | ||
```ts | ||
import { createRouter, toRouteMatcher } from 'radix3' | ||
import { createRouter, toRouteMatcher } from "radix3"; | ||
const router = createRouter({ | ||
routes: { | ||
'/foo': { m: 'foo' }, // Matches /foo only | ||
'/foo/**': { m: 'foo/**' }, // Matches /foo/<any> | ||
'/foo/bar': { m: 'foo/bar' }, // Matches /foo/bar only | ||
'/foo/bar/baz': { m: 'foo/bar/baz' }, // Matches /foo/bar/baz only | ||
'/foo/*/baz': { m: 'foo/*/baz' } // Matches /foo/<any>/baz | ||
} | ||
}) | ||
"/foo": { m: "foo" }, // Matches /foo only | ||
"/foo/**": { m: "foo/**" }, // Matches /foo/<any> | ||
"/foo/bar": { m: "foo/bar" }, // Matches /foo/bar only | ||
"/foo/bar/baz": { m: "foo/bar/baz" }, // Matches /foo/bar/baz only | ||
"/foo/*/baz": { m: "foo/*/baz" }, // Matches /foo/<any>/baz | ||
}, | ||
}); | ||
const matcher = toRouteMatcher(router) | ||
const matcher = toRouteMatcher(router); | ||
const matches = matcher.matchAll('/foo/bar/baz') | ||
const matches = matcher.matchAll("/foo/bar/baz"); | ||
@@ -140,12 +140,12 @@ // [ | ||
```ts | ||
import { exportMatcher, createMatcherFromExport } from 'radix3' | ||
import { exportMatcher, createMatcherFromExport } from "radix3"; | ||
// Assuming you already have a matcher | ||
// you can export this to a JSON-type object | ||
const json = exportMatcher(matcher) | ||
const json = exportMatcher(matcher); | ||
// and then rehydrate this later | ||
const newMatcher = createMatcherFromExport(json) | ||
const newMatcher = createMatcherFromExport(json); | ||
const matches = newMatcher.matchAll('/foo/bar/baz') | ||
const matches = newMatcher.matchAll("/foo/bar/baz"); | ||
``` | ||
@@ -165,2 +165,3 @@ | ||
<!-- Badges --> | ||
[npm-version-src]: https://img.shields.io/npm/v/radix3?style=flat&colorA=18181B&colorB=F0DB4F | ||
@@ -167,0 +168,0 @@ [npm-version-href]: https://npmjs.com/package/radix3 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14
-6.67%8
14.29%172
0.58%30730
-2.42%586
-28.36%