{"_id":"@axolo/egg-route-match","_rev":"3-b3bc7b2b8f388a3236c2dbd3a3f4244a","name":"@axolo/egg-route-match","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@axolo/egg-route-match","version":"0.1.0","author":{"name":"axolo"},"license":"MIT","_id":"@axolo/egg-route-match@0.1.0","maintainers":[{"name":"axolo","email":"fangyueming@foxmail.com"}],"dist":{"shasum":"e12a27bed35034706a83c25632d007741b1bfc7d","tarball":"https://registry.npmjs.org/@axolo/egg-route-match/-/egg-route-match-0.1.0.tgz","fileCount":3,"integrity":"sha512-UN583WKgX2qjspPLBOR8dlxN23v55RsvSv1mSRRUsso8M7X4WAMMIfFZKSiWBElccFlLTL+huwCtw3Uy/aGPGA==","signatures":[{"sig":"MEUCIQDNcYk4aScBWSrNr9RBBTXdAyR+p5C8kbQeSIM5vjRKSAIgJA/1M0Ahw8yplBnk3Ik+RQPaX/2kvg+5RULq1W1aYuU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4228},"main":"src/index.js","type":"commonjs","gitHead":"b0ca6d59d11059cb3cc67d4863748bdcd95edda7","scripts":{"test":"node --test test/index.test.js"},"_npmUser":{"name":"axolo","email":"fangyueming@foxmail.com"},"_npmVersion":"11.8.0","description":"Match route of egg.js by request object.","directories":{},"_nodeVersion":"24.13.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/egg-route-match_0.1.0_1776753065771_0.19259057114429434","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@axolo/egg-route-match","version":"0.1.1","keywords":["egg.js","route","match"],"author":{"name":"axolo"},"license":"MIT","_id":"@axolo/egg-route-match@0.1.1","maintainers":[{"name":"axolo","email":"fangyueming@foxmail.com"}],"homepage":"https://github.com/axolo/egg-route-match#readme","bugs":{"url":"https://github.com/axolo/egg-route-match/issues"},"dist":{"shasum":"a0b0f939e5af62a8427f339f78ab812988d26bc7","tarball":"https://registry.npmjs.org/@axolo/egg-route-match/-/egg-route-match-0.1.1.tgz","fileCount":4,"integrity":"sha512-yrJ9/zAqFJbirnJZ3n8oVB64UPfWBFeMWDCPj18Dr/atnLdKCkLXdh0Kn7XFLjE68B48H1/fxErwdeiVJBJojA==","signatures":[{"sig":"MEYCIQCWjetfyRSq6L3gHog1Zd8u/QV98WEub0bFxSUcZaxa2AIhAPvabsD1enDYxk84hvCUqu5+lxvbzWDdEzCDCOlDEdc8","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4321},"main":"dist/index.js","type":"commonjs","gitHead":"e73f10915c1852e36fdf37449757ba3a3832684e","scripts":{"test":"node --test test/index.test.js","build":"rollup -c"},"_npmUser":{"name":"axolo","email":"fangyueming@foxmail.com"},"repository":{"url":"git+https://github.com/axolo/egg-route-match.git","type":"git"},"_npmVersion":"10.8.2","description":"Match route of egg.js by request object.","directories":{},"_nodeVersion":"20.20.2","_hasShrinkwrap":false,"devDependencies":{"rollup":"^4.60.2","@rollup/plugin-terser":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/egg-route-match_0.1.1_1776911731419_0.19246684296594174","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@axolo/egg-route-match","version":"0.1.2","description":"Match route of egg.js by request object.","license":"MIT","author":{"name":"axolo"},"homepage":"https://github.com/axolo/egg-route-match#readme","repository":{"type":"git","url":"git+https://github.com/axolo/egg-route-match.git"},"type":"commonjs","main":"dist/index.js","keywords":["egg.js","route","match"],"scripts":{"build":"rollup -c","test":"node --test test/index.test.js"},"devDependencies":{"@rollup/plugin-terser":"^1.0.0","rollup":"^4.60.2"},"_id":"@axolo/egg-route-match@0.1.2","gitHead":"e89dd0de215aa2f2db6fd63ea5c2ccfe18e311f6","bugs":{"url":"https://github.com/axolo/egg-route-match/issues"},"_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-8Zs5lAngdr3F42sr/LOe24PFYsdV6G7nv0owcaRLTZRqh778DGZO1TkNi8ze0uplS+VgGlB16F/a9Eb1rriZAg==","shasum":"530330629adf4914dd8692d67d0f9d34cee6df1b","tarball":"https://registry.npmjs.org/@axolo/egg-route-match/-/egg-route-match-0.1.2.tgz","fileCount":4,"unpackedSize":4321,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@axolo%2fegg-route-match@0.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDGW60Ie4lKR6ATLocFzWsJDFyI+teZ6BtIf2uWPv0WJAIhANQV8n6hzGawUPVLq+g4hhBZP8LZ/kZ8sD0XeTV/j3vZ"}]},"_npmUser":{"name":"axolo","email":"fangyueming@foxmail.com"},"directories":{},"maintainers":[{"name":"axolo","email":"fangyueming@foxmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/egg-route-match_0.1.2_1777002171029_0.10945901053089191"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-21T06:31:05.641Z","modified":"2026-04-24T03:42:51.518Z","0.1.0":"2026-04-21T06:31:05.908Z","0.1.1":"2026-04-23T02:35:31.580Z","0.1.2":"2026-04-24T03:42:51.238Z"},"bugs":{"url":"https://github.com/axolo/egg-route-match/issues"},"author":{"name":"axolo"},"license":"MIT","homepage":"https://github.com/axolo/egg-route-match#readme","keywords":["egg.js","route","match"],"repository":{"type":"git","url":"git+https://github.com/axolo/egg-route-match.git"},"description":"Match route of egg.js by request object.","maintainers":[{"name":"axolo","email":"fangyueming@foxmail.com"}],"readme":"# egg-route-match\n\n一个轻量级的 [Egg.js] 路由匹配函数，用于在请求对象和路由表之间进行匹配。\n\n## 特性\n\n- 简单易用的 API\n- 支持动态路由参数（如 `/user/:id`）\n- 支持多种 HTTP 方法\n- 轻量级，无依赖\n\n## 安装\n\n```bash\nnpm i @axolo/egg-route-match\n```\n\n## 使用\n\n```javascript\nconst matchRoute = require('@axolo/egg-route-match');\n\n// 请求对象\nconst req = {\n  method: 'GET',\n  path: '/user/123'\n};\n\n// 路由表（来自 Egg.js 的 app.router.stack）\nconst routes = [\n  { methods: ['GET', 'HEAD'], path: '/user/:id' },\n  { methods: ['POST'], path: '/user' },\n  { methods: ['GET'], path: '/posts' }\n];\n\n// 匹配路由\nconst matched = matchRoute(req, routes);\n\nconsole.log(matched);\n// 输出: { method: 'GET', path: '/user/:id' }\n```\n\n## API\n\n### matchRoute(req, routes)\n\n根据请求对象和路由表，返回匹配的路由对象。\n\n#### 参数\n\n- `req` (Object): 请求对象\n  - `method` (String): HTTP 方法，如 `'GET'`, `'POST'` 等\n  - `path` (String): 请求路径，如 `'/user/123'`\n- `routes` (Array): 路由表，来自 Egg.js 的 `app.router.stack`\n  - 每个路由对象包含:\n    - `methods` (Array): 支持的 HTTP 方法数组\n    - `path` (String): 路由路径，支持动态参数\n\n#### 返回\n\n- `Object|null`: 匹配的路由对象，包含 `method` 和 `path` 属性；如果没有匹配则返回 `null`\n\n#### 示例\n\n```javascript\n// 静态路由匹配\nmatchRoute(\n  { method: 'GET', path: '/posts' },\n  [{ methods: ['GET'], path: '/posts' }]\n);\n// 返回: { method: 'GET', path: '/posts' }\n\n// 动态路由匹配\nmatchRoute(\n  { method: 'GET', path: '/user/123' },\n  [{ methods: ['GET'], path: '/user/:id' }]\n);\n// 返回: { method: 'GET', path: '/user/:id' }\n\n// 多方法匹配\nmatchRoute(\n  { method: 'HEAD', path: '/user/123' },\n  [{ methods: ['GET', 'HEAD'], path: '/user/:id' }]\n);\n// 返回: { method: 'HEAD', path: '/user/:id' }\n\n// 不匹配的情况\nmatchRoute(\n  { method: 'POST', path: '/user/123' },\n  [{ methods: ['GET'], path: '/user/:id' }]\n);\n// 返回: null\n```\n\n## 测试\n\n```bash\nnpm test\n```\n\n## License\n\nMIT\n\n[Egg.js]: https://eggjs.org/\n","readmeFilename":"README.md"}