{"id":44631612,"url":"https://github.com/bluet/anyroute.js","last_synced_at":"2026-02-14T16:35:07.596Z","repository":{"id":57181001,"uuid":"57434462","full_name":"bluet/anyroute.js","owner":"bluet","description":"A flexable lightweight router you can use in nodejs and browser. No dependency.","archived":false,"fork":false,"pushed_at":"2025-11-25T11:25:29.000Z","size":193,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-28T17:05:18.119Z","etag":null,"topics":["browser","dispatcher","fossa-status","hacktoberfest","handler","nodejs","path","payload","router","shortcut","uri-parser","url"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bluet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-30T08:53:17.000Z","updated_at":"2025-11-25T11:25:25.000Z","dependencies_parsed_at":"2023-02-10T11:45:49.773Z","dependency_job_id":null,"html_url":"https://github.com/bluet/anyroute.js","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/bluet/anyroute.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluet%2Fanyroute.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluet%2Fanyroute.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluet%2Fanyroute.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluet%2Fanyroute.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluet","download_url":"https://codeload.github.com/bluet/anyroute.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluet%2Fanyroute.js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29449374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","dispatcher","fossa-status","hacktoberfest","handler","nodejs","path","payload","router","shortcut","uri-parser","url"],"created_at":"2026-02-14T16:35:06.947Z","updated_at":"2026-02-14T16:35:07.592Z","avatar_url":"https://github.com/bluet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Node.js CI](https://github.com/bluet/anyroute.js/actions/workflows/node.js.yml/badge.svg)](https://github.com/bluet/anyroute.js/actions/workflows/node.js.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=anyroute\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=anyroute)\n[![Open Source Helpers](https://www.codetriage.com/bluet/anyroute.js/badges/users.svg)](https://www.codetriage.com/bluet/anyroute.js) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbluet%2Fanyroute.js.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbluet%2Fanyroute.js?ref=badge_shield)\n \n[![npm version](https://img.shields.io/npm/v/anyroute.svg)](https://www.npmjs.org/package/anyroute)\n[![install size](https://packagephobia.now.sh/badge?p=anyroute)](https://packagephobia.now.sh/result?p=anyroute)\n[![npm downloads](https://img.shields.io/npm/dm/anyroute.svg)](http://npm-stat.com/charts.html?package=anyroute)\n[![GitHub license](https://img.shields.io/github/license/BlueT/anyroute.js.svg)](https://github.com/BlueT/anyroute.js/blob/master/LICENSE)\n\n# anyroute - lightweight router works anywhere\nA flexible lightweight router you can use in nodejs and browser. No dependency.\n\n# INSTALL\n\n`npm i anyroute`\n\nOr find help from:\n- https://www.npmjs.com/package/anyroute\n- https://github.com/BlueT/anyroute.js\n\n## SYNOPSIS\n\n~~~~ js\nconst {Anyroute, MatchResult} = require('anyroute');\nconst anyroute = new Anyroute;\n\nanyroute.set('/happy/:foo/and/:bar', (params) =\u003e { console.log(\"Happy \" + params.foo + \" and \" + params.bar ); return params.foo + params.bar; });\n\nlet foobar = anyroute.get('/happy/trees/and/kitties').run();\n// Happy trees and kitties\n// foobar: treeskitties\n\nanyroute.set('/:aaa/:bbb', (match) =\u003e {return match;})\n        .get('/doraemon/superman')\n        .run({'c':'c'}, (result) =\u003e console.log(result));\n// { 'aaa': 'doraemon', 'bbb': 'superman', 'c': 'c' }\n\nanyroute.notfound(function (matchResult) {\n        // call when NO exact match found\n        // matchResult is an MatchResult Object\n        return matchResult.payload.foo + matchResult.payload.and;\n});\n~~~~\n\n\n## Setter\n\nDefine a route and placeholder.\nReturns error (if any), the handler been set, and an empty payload.\n\n~~~~ js\nfunction handler () {};\nfunction handler_post () {};\n\nanyroute.set('/collection/:cid/tab/:tabID', handler);\n// If no feat (a tag) has been set, means 'default'.\n\nvar ret = anyroute.set('/collection/:cid/tab/:tabID', handler, 'default');\n// When a handler of a feat has previously been set,\n// it'll overwrite with the new, and return a message in err.\n// Returns modified anyroute itself, too.\n\nvar ret = anyroute.set('/collection/:cid/tab/:tabID/', handler_post, 'post')\n// feat can be anything, just like a tag\n~~~~\n\n\n## Getter\n\n~~~~ js\nvar ret = anyroute.get('/collection/123/tab/456');\n// If no feat (a tag) has been set, means 'default'.\n// Returns MatchResult object\n\nvar ret = anyroute.get('/collection/ccc/tab/ttt', {user: 'keroro'});\n// You can put user's payload, and they'll be merged into one in return.\n// Custom payload with the same name will be override by get().\n// ret.payload: { user: 'keroro', cid: 'ccc', tabID: 'ttt' }\n\nvar ret = anyroute.get('/collection/foo/tab/bar', {cid: 'admin'}, 'all');\n// Also the 'all' means return all handlers from all feats.\n// ret.handler: \n//    { default: [Function: handler],\n//      post: [Function: handler_post] }\n\nvar ret = anyroute.get('/collection/abc/tab/xyz', {}, 'head');\n// Getting handler of a feat you've never set before,\n// will return the default handler, with a error message.\n// So you can have the fallback if you want.\n~~~~\n\n### run() shortcut\nCall with _run([object?: payload, function?: callback])_\n\n`run()` is a shortcut of `MatchResult.handler( MatchResult.payload )`.\n\n`run(callback)` is a shortcut of `callback( MatchResult.run() );`.\n\nAlso can do `run(additionalParams)` and `run(additionalParams, callback)`.\n\n~~~~ js\nvar result = ar.get(\"/collection/:cid/tab/:tabID\").run();\n\nvar ret = ar.get(\"/collection/:cid/tab/:tabID\", {}, \"default\");\nlet returnedByHandler = ret.run(req.body.data);\n// also can have custom payload here as first argument\n// similar to ret.handler(ret.payload)\n\nlet cid = ret.run({foo: bar}, (x) =\u003e x.cid);\nlet tab = ret.run((x) =\u003e x.tabID);\n// additional processing on data returned by pre-set handler\n~~~~\n\nBefore calling `run()`, you can set `.notfound(handleNotFound)` handler, which will be called if err occurred (path not found).\n\nFunction _handleNotFound_ will be called with _MatchResult_ as input parameter. `handleNotFound(MatchResult)`.\n\n~~~~ js\n// setup `notfound` handler\nanyroute.notfound(function (matchResult) {\n        // call when NO exact match found\n        // matchResult is an MatchResult Object\n        return matchResult.payload.foo + matchResult.payload.bar;\n});\n~~~~\n\n### MatchResult\n~~~~ js\nMatchResult {\n  err: undefined,\n  handler: [Function: handler],\n  payload: { foo: 'forty', bar: 'bobs', and: 'adam' },\n  default: undefined }\n~~~~\n\n\n## License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbluet%2Fanyroute.js.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbluet%2Fanyroute.js?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluet%2Fanyroute.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluet%2Fanyroute.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluet%2Fanyroute.js/lists"}