{"name":"radix3","version":"0.2.1","description":"Lightweight and fast router for JavaScript based on Radix Tree","repository":{"type":"git","url":"git+https://github.com/unjs/radix3.git"},"license":"MIT","sideEffects":false,"type":"module","exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.cjs","import":"./dist/index.mjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","devDependencies":{"0x":"^5.4.1","@nuxtjs/eslint-config-typescript":"^11.0.0","@vitest/coverage-c8":"^0.24.3","autocannon":"^7.10.0","benchmark":"^2.1.4","changelogen":"^0.3.2","eslint":"^8.25.0","jiti":"^1.16.0","listhen":"^0.3.4","ohmyfetch":"^0.4.19","standard-version":"^9.5.0","typescript":"^4.8.4","unbuild":"^0.9.2","vitest":"^0.24.3"},"packageManager":"pnpm@7.13.4","scripts":{"bench":"node ./benchmark/direct.mjs","bench:http":"node ./benchmark/http.mjs","bench:profile":"0x -o -D benchmark/.profile -- node ./benchmark/direct.mjs","build":"unbuild","dev":"vitest","lint":"eslint --ext .ts,.mjs .","playground":"pnpm jiti ./playground.ts","release":"pnpm test && pnpm build && changelogen --release && git push --follow-tags && pnpm publish","test":"pnpm lint && vitest run"},"bugs":{"url":"https://github.com/unjs/radix3/issues"},"homepage":"https://github.com/unjs/radix3#readme","_id":"radix3@0.2.1","_integrity":"sha512-FnhArTl5Tq7dodiLeSPKrDUyCQuJqEncP8cKdyy399g8F/cz7GH6FmzA3Rkosu2IZMkpswFFwXfb2ERSiL06pg==","_resolved":"/private/var/folders/s0/k4lcb4b50bj9r4fch4_1h_l40000gn/T/15050d6608b6cde18f9dadca5f4d242a/radix3-0.2.1.tgz","_from":"file:radix3-0.2.1.tgz","_nodeVersion":"16.17.0","_npmVersion":"8.15.0","dist":{"integrity":"sha512-FnhArTl5Tq7dodiLeSPKrDUyCQuJqEncP8cKdyy399g8F/cz7GH6FmzA3Rkosu2IZMkpswFFwXfb2ERSiL06pg==","shasum":"77e66a41c7ba5600a8bc137fd259ef661d314418","tarball":"http://registry-npm.ywwl.com/radix3/download/radix3-0.2.1.tgz","fileCount":6,"unpackedSize":20884,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHTSxLbGnMtxFeTQ5pVAIJU7GEKehLITonF1pz9sbea0AiEAj9OK9pqgxqzSuyKwAvOsPzC9tKXjqWhR69oJB18xar8="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjSvItACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoHLg/9F5WFrcbmcNybC157esalyLhOAu/n+z9GGAhcofFrYvWVLtR2\r\nYe7S1wtmzGBFw6h8dHWP0TcEnjrPi+RdyMQccDqKTRy32/oL0ItGxBEGytYO\r\njAL9+1eObQmeCphnPMLnjXfHQzzpNNXWphbqTSMojAZ5yQ2Th/12UhqF624k\r\nTH496zsdDBsnyNBaxZyFNtmGV5i0bVQ2JecpqzZnX+K9TlExza0UeABCGoDx\r\nGqR91sOgM6FMHfTifw/qwVisbq+hiIGbmlNZ8IN3qK/5WRnVGjwYmxrTTB32\r\nhsWbrqhuga7OEAyQl2LIS+yl/uwWVu4DOczd9IARRbmehkNqaiuLmfXexLi5\r\nce9NhqsXN4OJRyc9scSIgYS5LCGcqpAvxbrt384tdYJpycdarCYoSKzbvvWp\r\npSBhpAFpMfm5b0jKaQ24rLQjyJY0SIMSG7iWktsaL5/WP+ZDX6Q37koXeJaW\r\nJvSjrq4dbJbAh76nAAagOwJtEsxpxk+nyc4+hXNtGQXoZsSkSLjzE6/nnA2b\r\nbrDvArhZriTq2+US9WiKZchd6v3Ppo3vAiAOB5FYrsgJkrHEjF1ePt9Ja0AI\r\nrm35jkK2scs8RIHXbYkARRwK30pxRiGly2OclbVURT/+dED2l5FH1U46zWLD\r\nwCM7QMtFPQ4SCDPJlesKmDdxgSWOmtKeCOk=\r\n=j50h\r\n-----END PGP SIGNATURE-----\r\n","size":5235,"noattachment":false,"key":"/radix3/-/radix3-0.2.1.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/radix3_0.2.1_1665856045098_0.2087978452937138"},"_hasShrinkwrap":false,"readme":"# 🌳 radix3\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![Codecov][codecov-src]][codecov-href]\n[![License][license-src]][license-href]\n[![JSDocs][jsdocs-src]][jsdocs-href]\n\nLightweight and fast router for JavaScript based on [Radix Tree](https://en.wikipedia.org/wiki/Radix_tree).\n\n## Usage\n\n**Install package:**\n\n```sh\n# npm\nnpm i radix3\n\n# yarn\nyarn add radix3\n\n# pnpm\npnpm i radix3\n```\n\n**Import:**\n\n```js\n// ESM\nimport { createRouter } from \"radix3\";\n\n// CJS\nconst { createRouter } = require(\"radix3\");\n```\n\n**Create a router instance and insert routes:**\n\n```js\nconst router = createRouter(/* options */);\n\nrouter.insert(\"/path\", { payload: \"this path\" });\nrouter.insert(\"/path/:name\", { payload: \"named route\" });\nrouter.insert(\"/path/foo/**\", { payload: \"wildcard route\" });\nrouter.insert(\"/path/foo/**:name\", { payload: \"named wildcard route\" });\n```\n\n**Match route to access matched data:**\n\n```js\nrouter.lookup(\"/path\");\n// { payload: 'this path' }\n\nrouter.lookup(\"/path/fooval\");\n// { payload: 'named route', params: { name: 'fooval' } }\n\nrouter.lookup(\"/path/foo/bar/baz\");\n// { payload: 'wildcard route' }\n\nrouter.lookup(\"/\");\n// null (no route matched for/)\n```\n\n## Methods\n\n### `router.insert(path, data)`\n\n`path` can be static or using `:placeholder` or `**` for wildcard paths.\n\nThe `data` object will be returned on matching params. It should be an object like `{ handler }` and not containing reserved keyword `params`.\n\n### `router.lookup(path)`\n\nReturns matched data for `path` with optional `params` key if mached route using placeholders.\n\n### `router.remove(path)`\n\nRemove route matching `path`.\n\n## Options\n\nYou can initialize router instance with options:\n\n```ts\nconst router = createRouter({\n  strictTrailingSlash: true,\n  routes: {\n    \"/foo\": {},\n  },\n});\n```\n\n- `routes`: An object specifying initial routes to add\n- `strictTrailingSlash`: By default router ignored trailing slash for matching and adding routes. When set to `true`, matching with trailing slash is different.\n\n### Route Matcher\n\nCreates a multi matcher from router tree that can match **all routes** matching path:\n\n```ts\nimport { createRouter, toRouteMatcher } from \"radix3\";\n\nconst router = createRouter({\n  routes: {\n    \"/foo\": { m: \"foo\" }, // Matches /foo only\n    \"/foo/**\": { m: \"foo/**\" }, // Matches /foo/<any>\n    \"/foo/bar\": { m: \"foo/bar\" }, // Matches /foo/bar only\n    \"/foo/bar/baz\": { m: \"foo/bar/baz\" }, // Matches /foo/bar/baz only\n    \"/foo/*/baz\": { m: \"foo/*/baz\" }, // Matches /foo/<any>/baz\n  },\n});\n\nconst matcher = toRouteMatcher(router);\n\nconst matches = matcher.matchAll(\"/foo/bar/baz\");\n\n// [\n//   {\n//     \"m\": \"foo/**\",\n//   },\n//   {\n//     \"m\": \"foo/*/baz\",\n//   },\n//   {\n//     \"m\": \"foo/bar/baz\",\n//   },\n// ]\n```\n\n### Route Matcher Export\n\nIt is also possible to export and then rehydrate a matcher from pre-compiled rules.\n\n```ts\nimport { exportMatcher, createMatcherFromExport } from \"radix3\";\n\n// Assuming you already have a matcher\n// you can export this to a JSON-type object\nconst json = exportMatcher(matcher);\n\n// and then rehydrate this later\nconst newMatcher = createMatcherFromExport(json);\n\nconst matches = newMatcher.matchAll(\"/foo/bar/baz\");\n```\n\n## Performance\n\nSee [benchmark](./benchmark).\n\n## License\n\nBased on original work of [`charlieduong94/radix-router`](https://github.com/charlieduong94/radix-router)\nby [Charlie Duong](https://github.com/charlieduong94) (MIT)\n\n[MIT](./LICENSE) - Made with ❤️\n\n<!-- Badges -->\n\n[npm-version-src]: https://img.shields.io/npm/v/radix3?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/radix3\n[npm-downloads-src]: https://img.shields.io/npm/dm/radix3?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/radix3\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/radix3/main?style=flat&colorA=18181B&colorB=F0DB4F\n[codecov-href]: https://codecov.io/gh/unjs/radix3\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/radix3?style=flat&colorA=18181B&colorB=F0DB4F\n[bundle-href]: https://bundlephobia.com/result?p=radix3\n[license-src]: https://img.shields.io/github/license/unjs/radix3.svg?style=flat&colorA=18181B&colorB=F0DB4F\n[license-href]: https://github.com/unjs/radix3/blob/main/LICENSE\n[jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F\n[jsdocs-href]: https://www.jsdocs.io/package/radix3\n","publish_time":1665856045299,"_cnpm_publish_time":1665856045299,"dist-tags":{"latest":"1.1.2"}}