{"_id":"routes","_rev":"4221128","name":"routes","description":"Minimalist route matching for javascript","dist-tags":{"latest":"2.1.0"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"time":{"modified":"2026-03-04T17:20:49.000Z","created":"2011-02-06T08:47:46.615Z","2.1.0":"2015-07-09T22:12:19.222Z","2.0.0":"2014-11-22T15:49:40.729Z","1.2.0":"2014-07-21T17:57:49.451Z","1.1.0":"2014-04-15T21:24:56.790Z","1.0.0":"2014-04-14T20:03:51.308Z","0.3.0":"2014-04-08T02:37:47.490Z","0.2.0":"2013-05-09T20:12:13.646Z","0.1.1":"2012-04-24T01:15:48.090Z","0.1.0":"2011-02-06T08:47:46.615Z"},"users":{},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"versions":{"2.1.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"2.1.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"dist/routes","directories":{"lib":"."},"scripts":{"test":"make test","prepublish":"mkdir -p dist/ && browserify --require ./index --standalone routes > dist/routes.js"},"engines":{"node":"*"},"devDependencies":{"browserify":"^3.30.4"},"gitHead":"f85efed8b5a626130a4a549fdf262f8e885ebb6d","bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"},"_id":"routes@2.1.0","_shasum":"475571192a48f99b6c065dd926bb75e8ae83e8a2","_from":".","_npmVersion":"2.7.4","_nodeVersion":"0.10.32","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"dist":{"shasum":"475571192a48f99b6c065dd926bb75e8ae83e8a2","size":6676,"noattachment":false,"key":"/routes/-/routes-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-2.1.0.tgz"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"publish_time":1436479939222,"_hasShrinkwrap":false,"_cnpm_publish_time":1436479939222,"_cnpmcore_publish_time":"2021-12-17T04:14:00.840Z"},"2.0.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"2.0.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"dist/routes","directories":{"lib":"."},"scripts":{"test":"make test","prepublish":"mkdir -p dist/ && browserify --require ./index --standalone routes > dist/routes.js"},"engines":{"node":"*"},"devDependencies":{"browserify":"^3.30.4"},"gitHead":"fda0ea1b0eb9ae56d0926a381fe8365bda1573b7","bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"},"_id":"routes@2.0.0","_shasum":"0e6291e4b54e9114088b23513b10ec7edb80ea01","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"dist":{"shasum":"0e6291e4b54e9114088b23513b10ec7edb80ea01","size":6316,"noattachment":false,"key":"/routes/-/routes-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-2.0.0.tgz"},"publish_time":1416671380729,"_hasShrinkwrap":false,"_cnpm_publish_time":1416671380729,"_cnpmcore_publish_time":"2021-12-17T04:14:01.379Z"},"1.2.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"1.2.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"dist/routes","directories":{"lib":"."},"scripts":{"test":"make test","prepublish":"mkdir -p dist/ && browserify --require ./index --standalone routes > dist/routes.js"},"engines":{"node":"*"},"devDependencies":{"browserify":"^3.30.4"},"gitHead":"26ba8144a2b63c8646755178cae7ca54dac14f11","bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"},"_id":"routes@1.2.0","_shasum":"f688cd65f9c449d078645690ba3aa849e1a2d33f","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"dist":{"shasum":"f688cd65f9c449d078645690ba3aa849e1a2d33f","size":6224,"noattachment":false,"key":"/routes/-/routes-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-1.2.0.tgz"},"publish_time":1405965469451,"_hasShrinkwrap":false,"_cnpm_publish_time":1405965469451,"_cnpmcore_publish_time":"2021-12-17T04:14:01.616Z"},"1.1.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"1.1.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"dist/routes","directories":{"lib":"."},"scripts":{"test":"make test","prepublish":"mkdir -p dist/ && browserify --require ./index --standalone routes > dist/routes.js"},"engines":{"node":"*"},"devDependencies":{"browserify":"^3.30.4"},"bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"},"_id":"routes@1.1.0","dist":{"shasum":"af3c2285a3f9d887ff0c14934fc54e1cf8f9b7ff","size":6142,"noattachment":false,"key":"/routes/-/routes-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-1.1.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"publish_time":1397597096790,"_hasShrinkwrap":false,"_cnpm_publish_time":1397597096790,"_cnpmcore_publish_time":"2021-12-17T04:14:01.878Z"},"1.0.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"1.0.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"dist/routes","directories":{"lib":"."},"scripts":{"test":"make test","prepublish":"mkdir -p dist/ && browserify --require ./index --standalone routes > dist/routes.js"},"engines":{"node":"*"},"devDependencies":{"browserify":"^3.30.4"},"bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"},"_id":"routes@1.0.0","dist":{"shasum":"a897d1133b0e12640d8eb9e461a7ca2a3e6f994b","size":4993,"noattachment":false,"key":"/routes/-/routes-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-1.0.0.tgz"},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"publish_time":1397505831308,"_hasShrinkwrap":false,"_cnpm_publish_time":1397505831308,"_cnpmcore_publish_time":"2021-12-17T04:14:02.073Z"},"0.3.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"0.3.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"dist/routes","directories":{"lib":"."},"scripts":{"test":"make test","prepublish":"mkdir -p dist/ && browserify --require ./index --standalone routes > dist/routes.js"},"engines":{"node":"*"},"devDependencies":{"browserify":"^3.30.4"},"bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"},"_id":"routes@0.3.0","dist":{"shasum":"726f0801b136cc8a83f26031239160e307cb264f","size":4975,"noattachment":false,"key":"/routes/-/routes-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-0.3.0.tgz"},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"publish_time":1396924667490,"_hasShrinkwrap":false,"_cnpm_publish_time":1396924667490,"_cnpmcore_publish_time":"2021-12-17T04:14:02.299Z"},"0.2.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"0.2.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"https://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"index","directories":{"lib":"."},"scripts":{"test":"make test"},"engines":{"node":"*"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"},"_id":"routes@0.2.0","dist":{"shasum":"69e8f39fcdd15f616ce03460e7982cd1997c15ed","size":4468,"noattachment":false,"key":"/routes/-/routes-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-0.2.0.tgz"},"_from":".","_npmVersion":"1.2.19","_npmUser":{"name":"raynos","email":"raynos2@gmail.com"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"publish_time":1368130333646,"_hasShrinkwrap":false,"_cnpm_publish_time":1368130333646,"_cnpmcore_publish_time":"2021-12-17T04:14:02.526Z"},"0.1.1":{"name":"routes","description":"Minimalist route matching for javascript","version":"0.1.1","homepage":"https://github.com/aaronblohowiak/routes.js","repository":{"type":"git","url":"git://github.com/aaronblohowiak/routes.js.git"},"author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"index","directories":{"lib":"."},"scripts":{"test":"make test"},"engines":{"node":"*"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"_id":"routes@0.1.1","dependencies":{},"devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.18","_nodeVersion":"v0.7.9-pre","_defaultsLoaded":true,"dist":{"shasum":"b170cd1cdae129156c8759e251a1a53bffc1ebff","size":4359,"noattachment":false,"key":"/routes/-/routes-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-0.1.1.tgz"},"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"publish_time":1335230148090,"_hasShrinkwrap":false,"_cnpm_publish_time":1335230148090,"_cnpmcore_publish_time":"2021-12-17T04:14:02.750Z"},"0.1.0":{"name":"routes","description":"Minimalist route matching for javascript","version":"0.1.0","homepage":"https://github.com/aaronblohowiak/routes.js","repository":"https://github.com/aaronblohowiak/routes.js.git","author":{"name":"Aaron Blohowiak","email":"aaron.blohowiak@gmail.com","url":"http://github.com/aaronblohowiak"},"main":"index","directories":{"lib":"."},"scripts":{"test":"make test"},"engines":{"node":"*"},"_id":"routes@0.1.0","_engineSupported":true,"_npmVersion":"0.2.13-3","_nodeVersion":"v0.2.5","dist":{"shasum":"86245168969cb956aa7301bf4c8336d9f17245ed","size":4443,"noattachment":false,"key":"/routes/-/routes-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/routes/download/routes-0.1.0.tgz"},"publish_time":1296982066615,"maintainers":[{"name":"aaronblohowiak","email":""},{"name":"raynos","email":""}],"_hasShrinkwrap":false,"_cnpm_publish_time":1296982066615,"_cnpmcore_publish_time":"2021-12-17T04:14:02.952Z"}},"readme":"# Routes.js\n\n`routes` lets you easily dispatch based on url-style strings.  It comes with a default `Router` function that you can use to route http requests, but it also cleanly exposes the important functionality so you could also use it to perform more generic string pattern matching.\n\nThis might make it useful for things like:\n\n* URI routing\n* Cucumber-style pattern matching :)\n* Routing messages by channel name from an MQ\n* Dispatching hierarchical events by name\n\n## Alternative routers.\n\nThis module is no longer actively worked on. This module operates just fine as is,\n  however you might want to use a module that is under active maintenance:\n  \n - https://github.com/Matt-Esch/http-hash\n - https://github.com/glassresistor/i40\n - https://github.com/bevacqua/ruta3\n\n## Router Example:\n\nThe full range of `Path Formats` is documented below.\n\n```js\nvar Router = require('routes');\nvar router = Router();\nvar noop = function(){};\n\nrouter.addRoute(\"/articles/:title?\", noop);\nrouter.addRoute(\"/:controller/:action/:id.:format?\", noop);\n\nconsole.log(router.match(\"/articles\"));\nconsole.log(router.match(\"/articles/never-gonna-let-you-down\"));\nconsole.log(router.match(\"/posts/show/1.json\"));\n\n```\n\nThe output for `router.match(\"/posts/show/1.json\")` would be:\n```js\n{\n  params: {\n    controller: 'posts',\n    action: 'show',\n    id: '1',\n    format: 'json'\n  },\n  splats: [],\n  route: '/:controller/:action/:id.:format?',\n  fn: [Function],\n  next: [Function]\n}\n```\n\nIn the example above, `fn` would be the function that was passed into the router.\n\n\nI return this object instead of calling your function for you because you will likely want to add additional parameters from the current context to the function invocation. Ex:\n\n```js\nvar route = router.match(\"/posts/show/1.json\");\nroute.fn.apply(null, [req, res, route.params, route.splats]);\n```\n\n## Match Continuation\n\nThe object returned by `router.match` includes a `next` function you can use to continue matching against subsequent routes. Routes are evaluated in the order they are added to the router, so generally, you would add your most specific routes first and most ambiguous routes last. Using the `next` function allows you evaluate more ambiguous routes first.\n\n```js\nvar Router = require('routes');\nvar router = new Router();\n\nrouter.addRoute('/admin/*?', auth);\nrouter.addRoute('/admin/users', adminUsers);\n\nhttp.createServer(function (req, res) {\n  var path = url.parse(req.url).pathname;\n  var match = router.match(path);\n  match.fn(req, res, match);\n}).listen(1337)\n\n// authenticate the user and pass them on to\n// the next route, or respond with 403.\nfunction auth(req, res, match) {\n  if (checkUser(req)) {\n    match = match.next();\n    if (match) match.fn(req, res, match);\n    return;\n  }\n  res.statusCode = 403;\n  res.end()\n}\n\n// render the admin.users page\nfunction adminUsers(req, res, match) {\n  // send user list\n  res.statusCode = 200;\n  res.end();\n}\n```\n\n## Installation\n\n    npm install routes\n\n## Path Formats\n\nBasic string:\n\n    \"/articles\" will only match routes that == \"/articles\".\n\nNamed parameters:\n\n    \"/articles/:title\" will only match routes like \"/articles/hello\", but *not* \"/articles/\".\n\nOptional named parameters:\n\n    \"/articles/:title?\" will match \"/articles/hello\" AND \"/articles/\"\n\nPeriods before optional parameters are also optional:\n\n    \"/:n.:f?\" will match \"/1\" and \"/1.json\"\n\nSplaaaat! :\n\n    \"/assets/*\" will match \"/assets/blah/blah/blah.png\" and \"/assets/\".\n\n    \"/assets/*.*\" will match \"/assets/1/2/3.js\" as splats: [\"1/2/3\", \"js\"]\n\nMix splat with named parameters:\n\n    \"/account/:id/assets/*\" will match \"/account/2/assets/folder.png\" as params: {id: 2}, splats:[\"folder.png\"]\n\n\nNamed RegExp:\n\n    \"/lang/:lang([a-z]{2})\" will match \"/lang/en\" but not \"/lang/12\" or \"/lang/eng\"\n\nRaw RegExp:\n\n    /^\\/(\\d{2,3}-\\d{2,3}-\\d{4})\\.(\\w*)$/ (note no quotes, this is a RegExp, not a string.) will match \"/123-22-1234.json\". Each match group will be an entry in splats: [\"123-22-1234\", \"json\"]\n\n\n## Router API\n\nThe `Router()` that `routes` exposes has two functions: `addRoute` and `match`.\n\n`addRoute`: takes a `path` and a `fn`. Your `path` can match any of the formats in the \"Path Formats\" section.\n\n`match`: takes a `String` or `RegExp` and returns an object that contains the named `params`, `splats`, `route` (string that was matched against), the `fn` handler you passed in with `addRoute`, and a `next` function which will run `match` against subsequent routes.\n\n## Library API\n\n`match`: takes an array of `Routes`, and a `String`. It goes through `Routes` and returns an object for the first `Route` that matches the `String`, or `undefined` if none is found. The returned object contains `params`, `splats`, and `route`. `params` is an object containing the named matches, `splats` contains the unnamed globs (\"*\"), and `route` contains the original string that was matched against.\n\n`pathToRegExp`: takes a `path` string and an empty `keys` array, returns a RegExp and populates `keys` with the names of the match groups that the RegExp will match. This is largely an internal function but is provided in case someone wants to make a nifty string -> [RegExp, keys] utility.\n\n\n## Test\n\nClone the repo, cd to it, and:\n\n    make test\n\n## Credits\n\nThis library is an extraction and re-factor of the `connect` `router` middleware.  I found that connect-based routing worked reasonably well on the server side, but I wanted to do similar routing based on channel names when using `Push-It` and possibly for event names when using `Evan`.  So, I extracted the relevant goodness out of the `router` middleware and presented it here.  Big thanks to TJ Holowaychuk for writing the original `router` middleware.\n\n## License\n\nThis code is distributed under the MIT license, Copyright Aaron Blohowiak and TJ Holowaychuk 2011.\n","_attachments":{},"homepage":"https://github.com/aaronblohowiak/routes.js","bugs":{"url":"https://github.com/aaronblohowiak/routes.js/issues"}}