{"name":"wayfarer","version":"1.3.1","description":"A simple router built for minimalism and speed","main":"index.js","scripts":{"test":"NODE_ENV=test ./node_modules/mocha/bin/mocha --recursive --harmony-generators -R spec","coverage":"./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report text --recursive -- -R spec && rm -rf ./coverage/"},"repository":{"type":"git","url":"https://github.com/yoshuawuyts/wayfarer"},"keywords":["router","trie","minimalism","react"],"author":{"name":"Yoshua Wuyts","email":"i@yoshuawuyts.com"},"license":"MIT","bugs":{"url":"https://github.com/yoshuawuyts/wayfarer/issues"},"homepage":"https://github.com/yoshuawuyts/wayfarer","dependencies":{"routington":"^1.0.2"},"devDependencies":{"coveralls":"^2.10.0","istanbul":"^0.2.11","mocha":"^1.20.1","should":"^4.0.4"},"gitHead":"cfc02f05af11bf74cd8bf64b1c673deca779b9cb","_id":"wayfarer@1.3.1","_shasum":"cbd1b6e7be521430c2e58099a429aadfea1a7775","_from":".","_npmVersion":"2.1.3","_nodeVersion":"0.10.31","_npmUser":{"name":"yoshuawuyts","email":"i@yoshuawuyts.com"},"maintainers":[{"name":"yoshuawuyts","email":"i@yoshuawuyts.com"}],"dist":{"shasum":"cbd1b6e7be521430c2e58099a429aadfea1a7775","tarball":"http://registry-npm.ywwl.com/wayfarer/download/wayfarer-1.3.1.tgz","integrity":"sha512-SAIhBfcRfIgmheLm1kCdXSLWN0HlA+56gNg+FYRPamEnouKvI8H1SqjIbP6JisTGPEqYtzeLcBLwCiO216HWsw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGTXK1zXay7kdj1hT5+W17xN62S2mjacwXN2aUz5+SpJAiAKrDg+c8nK4f87cCgwCsgbqk4WnaMWdI/RR9Xjh1iCOQ=="}],"size":2911,"noattachment":false,"key":"/wayfarer/-/wayfarer-1.3.1.tgz"},"directories":{},"readme":"# wayfarer [![stability][0]][1]\n[![npm version][2]][3] [![build status][4]][5] [![test coverage][6]][7]\n[![downloads][8]][9] [![js-standard-style][10]][11]\n\nComposable [trie based](https://en.wikipedia.org/wiki/Trie) router.  It's\nfaster than traditional, linear, regular expression-matching routers, although\ninsignficantly, and scales with the number of routes.\n\nIf you're looking for a client-side router check out\n[sheet-router](https://github.com/yoshuawuyts/sheet-router). If you're looking\nfor a server router check out\n[server-router](https://github.com/yoshuawuyts/server-router).\n\n### features\n- works with any framework\n- built for speed\n- minimal dependencies\n- extensible\n\n## Installation\n```sh\n$ npm install wayfarer\n```\n\n## Usage\n```js\nvar wayfarer = require('wayfarer')\n\nvar router = wayfarer('/404')\n\nrouter.on('/', () => console.log('/'))\nrouter.on('/404', () => console.log('404 not found'))\nrouter.on('/:user', (params) => console.log('user is %s', params.user))\nrouter.on('/wildcard/*', (params) => console.log('wildcard path is %s', params.wildcard))\n\nrouter('tobi')\n// => 'user is tobi'\n\nrouter('/uh/oh')\n// => '404 not found'\n\nrouter('/wildcard/example/path')\n// => 'wildcard path is example/path'\n```\n\n## Subrouting\nRouters can be infinitely nested, allowing routing to be scoped per view.\nMatched params are passed into subrouters. Nested routes will call their\nparent's default handler if no path matches.\n```js\nvar r1 = wayfarer()\nvar r2 = wayfarer()\n\nr2.on('/child', () => console.log('subrouter trix!'))\nr1.on('/:parent', r2)\n\nr1('/dada/child')\n// => 'subrouter trix!'\n```\n\n## Walk\nSometimes it's necessary to walk the `trie` to apply transformations.\n```js\nvar walk = require('wayfarer/walk')\nvar wayfarer = require('wayfarer')\n\nvar router = wayfarer()\nrouter.on('/multiply', (x, y) => x * y)\nrouter.on('/divide', (x, y) => x / y)\n\nwalk(router, (route, cb) => {\n  var y = 2\n  return function (params, x) {\n    return cb(x, y)\n  }\n})\n\nrouter('/multiply', 4)\n// => 8\nrouter('/divide', 8)\n// => 4\n```\n\n## API\n### router = wayfarer(default)\nInitialize a router with a default route. Doesn't ignore querystrings and\nhashes.\n\n### router.on(route, cb(params, [arg1, ...]))\nRegister a new route. The order in which routes are registered does not matter.\nRoutes can register multiple callbacks. The callback can return values when\ncalled.\n\n### matchedRoute = router.match(route)\nMatches a route and returns an object. The returned object contains the properties `{cb, params, route}`. This method does not invoke the callback of a route. If no route matches, the default route will be returned. If no default route matches, an error will be thrown.\n\n### val = router(route, [arg1, ...])\nMatch a route and execute the corresponding callback. Alias: `router.emit()`.\nReturns a values from the matched route (e.g. useful for streams). Any\nadditional values will be passed to the matched route.\n\n## Internals\nWayfarer is built on an internal trie structure. If you want to build a router\nusing this trie structure it can be accessed through\n`require('wayfarer/trie')`. It exposes the following methods:\n- `trie = Trie()` - create a new trie\n- `node = trie.create(route)` - create a node at a path, and return a node\n- `node = trie.match(route)` - match a route on the the trie and return a node\n- `trie.mount(path, trie)` - mount a trie onto a node at route\n\n## Known issues\n### multiple nested partials don't match\nE.g. `/:foo/:bar/:baz` won't work. This is due `Trie.mount()` overriding child\npartial paths when mounted. I'll get around to fixing this at some point in the\nfuture, but if anyone wants to contribute a patch it'd most appreciated.\n\n## FAQ\n### Why did you build this?\nRouters like [react-router](https://github.com/rackt/react-router) are\ncomplicated solutions for a simple problem. In reality all that's needed is a\n[methodless](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html) router\nthat can define + match paths and can mount other routers to delegate requests.\n\n### Why isn't my route matching?\nWayfarer only compares strings. Before you pass in an url you probably want to\nstrip it of querystrings and hashes using the\n[pathname-match](https://github.com/yoshuawuyts/pathname-match) module.\n\n## See Also\n- [sheet-router](https://github.com/yoshuawuyts/sheet-router) - fast, modular\n  client-side router\n- [server-router](https://github.com/yoshuawuyts/server-router) - server router\n- [hash-match](https://github.com/sethvincent/hash-match) - easy\n  `window.location.hash` matching\n- [pathname-match](https://github.com/yoshuawuyts/pathname-match) - strip\n  querystrings and hashes from a url\n- [wayfarer-to-server](https://github.com/yoshuawuyts/wayfarer-to-server) -\n  Wrap wayfarer to provide HTTP method matching and `req, res` delegation\n\n## License\n[MIT](https://tldrlegal.com/license/mit-license)\n\n[0]: https://img.shields.io/badge/stability-2%20stable-brightgreen.svg?style=flat-square\n[1]: https://nodejs.org/api/documentation.html#documentation_stability_index\n[2]: https://img.shields.io/npm/v/wayfarer.svg?style=flat-square\n[3]: https://npmjs.org/package/wayfarer\n[4]: https://img.shields.io/travis/yoshuawuyts/wayfarer/master.svg?style=flat-square\n[5]: https://travis-ci.org/yoshuawuyts/wayfarer\n[6]: https://img.shields.io/codecov/c/github/yoshuawuyts/wayfarer/master.svg?style=flat-square\n[7]: https://codecov.io/github/yoshuawuyts/wayfarer\n[8]: http://img.shields.io/npm/dm/wayfarer.svg?style=flat-square\n[9]: https://npmjs.org/package/wayfarer\n[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\n[11]: https://github.com/feross/standard\n[12]: http://github.com/raynos/mercury\n[13]: http://github.com/raynos/virtual-dom\n","publish_time":1416158597448,"_cnpm_publish_time":1416158597448,"dist-tags":{"latest":"7.0.1"}}