{"name":"route-recognizer","version":"0.2.0","description":"A lightweight JavaScript library that matches paths against registered routes.","author":{"name":"Yehuda Katz"},"repository":{"type":"git","url":"git+https://github.com/tildeio/route-recognizer.git"},"devDependencies":{"broccoli-compile-modules":"1.0.1","broccoli-concat":"0.0.12","broccoli-funnel":"^0.1.6","broccoli-jshint":"~0.5.1","broccoli-merge-trees":"^0.2.1","broccoli-string-replace":"~0.1.0","do-you-even-bench":"^1.0.2","ember-cli":"1.13.1","glob":"^6.0.4"},"main":"dist/route-recognizer.js","bugs":{"url":"https://github.com/tildeio/route-recognizer/issues"},"homepage":"https://github.com/tildeio/route-recognizer","directories":{"test":"tests"},"scripts":{"test":"ember test","start":"ember test --server","build":"ember build","bench":"ember build && node ./bench/index.js"},"license":"MIT","gitHead":"19f58bf3ef5402c0d86ed4e107ae3124e0c187cb","_id":"route-recognizer@0.2.0","_shasum":"1d78c4984d5427c6d955934fe3cd34b758948e86","_from":".","_npmVersion":"3.8.6","_nodeVersion":"6.0.0","_npmUser":{"name":"rwjblue","email":"robert.w.jackson@me.com"},"maintainers":[{"name":"machty","email":"machty@gmail.com"},{"name":"rwjblue","email":"me@rwjblue.com"}],"dist":{"shasum":"1d78c4984d5427c6d955934fe3cd34b758948e86","tarball":"http://registry-npm.ywwl.com/route-recognizer/download/route-recognizer-0.2.0.tgz","integrity":"sha512-ITnKsFMRcPY67Gadk6zIj+UOottOSqBrj9W900iDjH3HAOD32al38GrfLmjuSJLRHUPZrgyu2VF+5YuYCHBDfw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICHEhO6XTI16xXe1tHcQnIzMmLCZ+0VcDCirC+kwG5QPAiEA9UeYmJM4xBYRn1hZkf3PKkCR+3OSoQtdZjikeq7eIhQ="}],"size":29325,"noattachment":false,"key":"/route-recognizer/-/route-recognizer-0.2.0.tgz"},"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/route-recognizer-0.2.0.tgz_1467134842675_0.7432584606576711"},"readme":"[![Build Status](https://travis-ci.org/tildeio/route-recognizer.svg)](https://travis-ci.org/tildeio/route-recognizer)\n\n# About\n`route-recognizer` is a lightweight JavaScript library (under 2k!) that\ncan be used as the recognizer for a more comprehensive router system\n(such as [`router.js`](https://github.com/tildeio/router.js)).\n\nIn keeping with the Unix philosophy, it is a modular library that does one\nthing and does it well.\n\n# Usage\n\nCreate a new router:\n\n```javascript\nvar router = new RouteRecognizer();\n```\n\nAdd a simple new route description:\n\n```javascript\nrouter.add([{ path: \"/posts\", handler: handler }]);\n```\n\nEvery route can optionally have a name:\n```javascript\nrouter.add([{ path: \"/posts\", handler: handler }], { as: \"routeName\"});\n```\n\nThe handler is an opaque object with no specific meaning to\n`route-recognizer`. A module using `route-recognizer` could\nuse functions or other objects with domain-specific semantics\nfor what to do with the handler.\n\nA route description can have handlers at various points along\nthe path:\n\n```javascript\nrouter.add([\n  { path: \"/admin\", handler: admin },\n  { path: \"/posts\", handler: posts }\n]);\n```\n\nRecognizing a route will return a list of the handlers and\ntheir associated parameters:\n\n```javascript\nvar result = router.recognize(\"/admin/posts\");\nresult === [\n  { handler: admin, params: {} },\n  { handler: posts, params: {} }\n];\n```\n\nDynamic segments:\n\n```javascript\nrouter.add([\n  { path: \"/posts/:id\", handler: posts },\n  { path: \"/comments\", handler: comments }\n]);\n\nresult = router.recognize(\"/posts/1/comments\");\nresult === [\n  { handler: posts, params: { id: \"1\" } },\n  { handler: comments, params: {} }\n];\n```\n\nA dynamic segment matches any character but `/`.\n\nStar segments:\n\n```javascript\nrouter.add([{ path: \"/pages/*path\", handler: page }]);\n\nresult = router.recognize(\"/pages/hello/world\");\nresult === [{ handler: page, params: { path: \"hello/world\" } }];\n```\n\n# Sorting\n\nIf multiple routes all match a path, `route-recognizer`\nwill pick the one with the fewest dynamic segments:\n\n```javascript\nrouter.add([{ path: \"/posts/edit\", handler: editPost }]);\nrouter.add([{ path: \"/posts/:id\", handler: showPost }]);\nrouter.add([{ path: \"/posts/new\", handler: newPost }]);\n\nvar result1 = router.recognize(\"/posts/edit\");\nresult1 === [{ handler: editPost, params: {} }];\n\nvar result2 = router.recognize(\"/posts/1\");\nresult2 === [{ handler: showPost, params: { id: \"1\" } }];\n\nvar result3 = router.recognize(\"/posts/new\");\nresult3 === [{ handler: newPost, params: {} }];\n```\n\nAs you can see, this has the expected result. Explicit\nstatic paths match more closely than dynamic paths.\n\nThis is also true when comparing star segments and other\ndynamic segments. The recognizer will prefer fewer star\nsegments and prefer using them for less of the match (and,\nconsequently, using dynamic and static segments for more\nof the match).\n\n# Building / Running Tests\n\nThis project uses Ember CLI and Broccoli for building and testing.\n\n## Getting Started\n\nRun the following commands to get going:\n\n```bash\nnpm install\nbower install\n```\n\nThe above assumes that you have `bower` installed globally (you can install\nvia `npm install -g bower` if you do not).\n\n## Running Tests\n\nRun the following:\n\n```\nnpm start\n```\n\nAt this point you can navigate to the url specified in the Testem UI (usually\nhttp://localhost:7357/). As you change the project the tests will rerun.\n\n## Building\n\n```\nnpm run build\n```\n","publish_time":1467134843773,"_cnpm_publish_time":1467134843773,"dist-tags":{"false":"0.2.10","latest":"0.3.4"}}