{"name":"radix3","version":"0.1.0","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":{"require":"./dist/index.cjs","import":"./dist/index.mjs"},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"unbuild","lint":"eslint --ext .ts,.mjs .","playground":"yarn jiti ./playground.ts","release":"yarn build && standard-version && git push --follow-tags && npm publish","test":"nyc --reporter=lcov mocha -r jiti/register tests/*.test.*"},"devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","@types/chai":"latest","@types/mocha":"latest","chai":"latest","eslint":"latest","jiti":"latest","mocha":"latest","nyc":"latest","standard-version":"latest","unbuild":"latest"},"gitHead":"27e6abe1bf15a58e8ff152d833ef4cf515ee8830","bugs":{"url":"https://github.com/unjs/radix3/issues"},"homepage":"https://github.com/unjs/radix3#readme","_id":"radix3@0.1.0","_nodeVersion":"14.18.1","_npmVersion":"8.1.0","dist":{"integrity":"sha512-OeAaZXMTjUn3u3kE4jF2m26AiA3ERoI5AwZZtUHByBPTDbU5BXVU7/M0+JbBrbwp7K7jn8RIk+hy522EldSvSQ==","shasum":"f06e7417eff16fd44bed1992af0bf25cabdc8668","tarball":"http://registry-npm.ywwl.com/radix3/download/radix3-0.1.0.tgz","fileCount":6,"unpackedSize":15953,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhnseVCRA9TVsSAnZWagAAMBwP+wW3MtAxVWAhw/cWgopp\n+AWXUin0njBSo3i6NL24ClrxB5Z+/LLthVX4k1NosukaYf//t0o4vjCHCFE2\n1j4bEp/Izh7TgjLdsLknkLM76ZIROkgk4p35V4ZIcziFw8kh1NJ31QE0PR9I\nb5xdwWE/A9009fAsvN42gO84b29FtMBUmSV1FyZC4l7EKKSwu0DwbwPH7LpX\nihPrm8qiRJDF2RJu/mACxZj5nHEY3o4wAXWCl8xiuOkjEYTzZm7vJ39i3Cwq\nxj2G+Z/DsB1l9JKewRsCOT3s9xiCtaQScdl82m8rdllzXxsAPOyhRTEZOPGn\n8/3fesNExWS1HB9yaT9qPK1IZ2Ik8kBljaHrSTiSGyph1xDsWd2mHKSmrOOe\nRlU2VZqH7mUfHPHCHu6226aUOmiokrQ5EWgH84HXhhl8JxuabF5L5C4e5Div\nh2Mn68Q71UbWm99qqms9mk3Feozzs+q4i2t1ZnlDnFKI6sC58+5Tw0JtLQ3r\nY/0kQ5GZcNAi9GWhsxlryQS3fqUZkLKSozw7Xf462bGU192YzvxNfZOCkpQS\nomAn84WbutM0NkCtgTE/sTGrCwRBBRRwjer1reoiwGOyibBrX4YK+4zwm477\nazxvPLF1xwAxOjEiaYUyo932y7RIDqjkns7R0fc0PpRIhjo34zGm9VtXq3Bz\nwfWQ\r\n=IAQL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCjNMnyUSCazXlhgrZT055Lfviptm/R0HH1//G880/7BAIgSi7sJ5AAotfArltLCjfdnhvo1TSwaVGxlteWj4IQw30="}],"size":4131,"noattachment":false,"key":"/radix3/-/radix3-0.1.0.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.1.0_1637795732933_0.052798505294535"},"_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":1637795733093,"_cnpm_publish_time":1637795733093,"dist-tags":{"latest":"1.1.2"}}