{"_id":"@arve.knudsen/sheet-router","_rev":"3-39da11b7b766cf072837d397cae3014a","name":"@arve.knudsen/sheet-router","description":"Fast, modular client router","dist-tags":{"latest":"4.2.5"},"versions":{"4.2.4":{"name":"@arve.knudsen/sheet-router","version":"4.2.4","description":"Fast, modular client router","main":"index.js","scripts":{"test":"standard && NODE_ENV=test tape test/*","test:cov":"standard && NODE_ENV=test istanbul cover test/*"},"repository":{"type":"git","url":"git+https://github.com/aknuds1/sheet-router.git"},"keywords":["client","router","modular","wayfarer","history","pushstate","single-page","spa","progressive"],"license":"MIT","dependencies":{"global":"^4.3.0","@arve.knudsen/wayfarer":"^6.4.1","xtend":"^4.0.1"},"devDependencies":{"dependency-check":"^2.5.1","istanbul":"^0.4.1","jsdom":"^9.4.2","noop2":"^2.0.0","sinon":"^1.17.5","standard":"^5.4.1","tape":"^4.4.0","virtual-dom":"^2.1.1"},"gitHead":"f26efbf73c303dddca7fbe606c4578aba5402f9f","bugs":{"url":"https://github.com/aknuds1/sheet-router/issues"},"homepage":"https://github.com/aknuds1/sheet-router#readme","_id":"@arve.knudsen/sheet-router@4.2.4","_shasum":"266a52c4658b299bdf22d172123ec909f95c3938","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.0","_npmUser":{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"},"dist":{"shasum":"266a52c4658b299bdf22d172123ec909f95c3938","tarball":"https://registry.npmjs.org/@arve.knudsen/sheet-router/-/sheet-router-4.2.4.tgz","integrity":"sha512-JGKeCihe3kNBwljqk4d1PvF8oKuQ0t93DBpuADsHfYy7xqLIajH0ES3UcdcocSTOa+86xUvRWjQLnpKpQ+rJHQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCnly0lUSeEfrBYExCctqY6s3/Q5PVjMJhXTtOMqMDO8AIhAIA6VEnuWROazwP1q4yMvPkLUflvCve82f19SmCcBKiW"}]},"maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/sheet-router-4.2.4.tgz_1488466684308_0.19475842965766788"}},"4.2.5":{"name":"@arve.knudsen/sheet-router","version":"4.2.5","description":"Fast, modular client router","main":"index.js","scripts":{"test":"standard && NODE_ENV=test tape test/*","test:cov":"standard && NODE_ENV=test istanbul cover test/*"},"repository":{"type":"git","url":"git+https://github.com/aknuds1/sheet-router.git"},"keywords":["client","router","modular","wayfarer","history","pushstate","single-page","spa","progressive"],"license":"MIT","dependencies":{"global":"^4.3.0","@arve.knudsen/wayfarer":"^6.4.1","xtend":"^4.0.1"},"devDependencies":{"dependency-check":"^2.5.1","istanbul":"^0.4.1","jsdom":"^9.4.2","noop2":"^2.0.0","sinon":"^1.17.5","standard":"^5.4.1","tape":"^4.4.0","virtual-dom":"^2.1.1"},"gitHead":"f6179155968c9a0609c72eb9e201ce6cc366ec46","bugs":{"url":"https://github.com/aknuds1/sheet-router/issues"},"homepage":"https://github.com/aknuds1/sheet-router#readme","_id":"@arve.knudsen/sheet-router@4.2.5","_shasum":"e863bfca992e6e227ff37edfcecbe571910fd24c","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.0","_npmUser":{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"},"dist":{"shasum":"e863bfca992e6e227ff37edfcecbe571910fd24c","tarball":"https://registry.npmjs.org/@arve.knudsen/sheet-router/-/sheet-router-4.2.5.tgz","integrity":"sha512-xu3mUQi44iNE8OZaMTaSPK84ypFIG786vFHlEgJauI1DJpbOd2eURoierZEBer2hRgxgkkd13zN6E02WmQ1mlg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCNf11Qo9bhsKZPfVc/DrIrVRnopcC+ZUUcYl+x+dGXjwIgTY/iEiNun6xsyUdcS8A8YQEm0KI5IjhAfm3EVCo9Tog="}]},"maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/sheet-router-4.2.5.tgz_1488471226011_0.285187351051718"}}},"readme":"# sheet-router [![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\nsheet-router is a fast, modular client-side router. It enables view composition\nand is tuned for performance by statically declaring routes in a\n[radix-trie][12]. Weighs `1.5KB` minified and gzipped.\n\n## Installation\n```sh\n$ npm install sheet-router\n```\n\n## Features\n- View composition through functions\n- Tuned for performance by generating a [radix-trie][12]\n- Not bound to any framework\n- Minimal dependencies and tiny code size\n- HTML5 history support\n- Catch and handle `<a href=\"\">` links\n\n## Usage\nsheet-router tries to make routing understandable and pleasant to work with. It\ndoes so by using a lisp-like structure which is internally compiled to an\nefficient data structure. Here each route takes either an array of children or\na callback, which are then translated to paths that take callbacks\n```js\nconst sheetRouter = require('sheet-router')\nconst html = require('bel')\n\n// default to `/404` if no path matches\nconst router = sheetRouter({ default: '/404' }, [\n  ['/', (params) => html`<div>Welcome to router land!</div>`],\n  ['/:username', (params) => html`<div>${params.username}</div>`, [\n    ['/orgs', (params) => html`<div>${params.username}'s orgs!</div>`]\n  ]],\n  ['/404', (params) => html`<div>Oh no, path not found!</div>`],\n])\n\nrouter('/hughsk/orgs')\n```\n\n### history\nInteracting with the browser history is a common action, sheet-router\nsupports this out of the box. When the `forwards` or `backwards` buttons in the\nbrowser are clicked, or `history.back` / `history.go` are called sheet-router\nwill update accordingly.\n```js\nconst history = require('sheet-router/history')\nhistory(function (href) {\n  router(href)\n  console.log('history changed: ' + href)\n})\n```\n\n### hash\nInteracting with hash changes is often a common fallback scenario for those who\ndon't have support for browser history. Whenever a `hashchange` event is\ntriggered, sheet-router will trigger an update as seen below. However in order\nto match hash prefixed routes, the `hash-match` module can be used to normalize\nroutes (ex: `#/foo` becomes `/foo`).\n```js\nconst hash = require('sheet-router/hash')\nconst match = require('hash-match')\nhash(function (href) {\n  router(match(href))\n  console.log('hash location changed: ' + href)\n})\n```\n\n### href\nIn HTML links are represented with `<a href=\"\">` style tags. Sheet-router can\nbe smart about these and handle them globally. This way there's no need to\nattach specific listeners to each link and static HTML templates can be\nupgraded seemlessly to include single-page routing.\n```js\nconst href = require('sheet-router/href')\nhref(function (href) {\n  router(href)\n  console.log('link was clicked: ' + href)\n})\n```\n\nYou can ignore specific links that you do not want to process through routing\nby adding the `data-no-routing` attribute.\n\n```html\n<a href=\"/my-external-link\" data-no-routing>Non routed link</a>\n<a href=\"/another-external-link\" data-no-routing=\"true\">Not routed either</a>\n```\n\nAlso, if you pass an optional `root` node reference as a second argument to `href`, it will never intercept clicks outside that node. This is useful when your app is confined to a widget in a larger document.\n\n```js\nhref(function (href) {\n  router(href)\n  console.log('link was clicked: ' + href)\n}, document.getElementById(\"app-root\"))\n```\n\n### qs\nSometimes [query strings][mdn-qs] must be decoded. In order to do this, the\n`./qs.js` file is included.\n```js\nconst qs = require('./qs')\nqs('https://www.npmjs.com/search?q=query+string')\n// => { q: 'query+string' }\n```\n\n### walk\nSometimes it's necessary to walk the `trie` to apply transformations. In order\nto access the raw callback and prevent unnecessary function calls we need to\ndisable the default thunking mechanism by passing `{ thunk: false }`:\n```js\nconst sheetRouter = require('sheet-router')\nconst walk = require('sheet-router/walk')\n\nconst router = sheetRouter({ thunk: false }, [\n  ['/multiply', (x, y) => x * y],\n  ['/divide', (x, y) => x / y]\n])\n\nwalk(router, (route, cb) => {\n  const 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\nWe could change our transformed function to be thunked by changing `walk` to\nreturn a function, and setting `{ thunk: 'match' }` so only the `match`\nfunction thunks. This is pretty advanced stuff, so don't sweat it too much -\nbut it's super useful to create performant frameworks!\n```js\nconst router = sheetRouter({ thunk: 'match' }, [\n  ['/foo', (x, y) => x * y],\n  ['/bar', (x, y) => x / y]\n])\n\nwalk(router, (route, cb) => {\n  const y = 2\n  return function (params) {\n    return function (x) {\n      return cb(x, y)\n    }\n  }\n})\n\nrouter('/multiply', 4)\n// => 8\nrouter('/multiply', 4)\n// => 8 (but this time around this is computed faster)\nrouter('/divide', 8)\n// => 4\n```\n\n### create-location\nSometimes you want to mirror the browser location API inside an object to use\ninside a framework. The hard part is to compute the new `href` from a set of\nchanges. `create-location` provides an API to do just that:\n```js\nconst createLocation = require('sheet-router/create-location')\n\ndocument.location = '/foo/bar#hey?beep=boop'\nvar location = createLocation()\n// => {\n//    pathname: '/',\n//    hash: '#hey',\n//    search: { beep: 'boop' },\n//    href: '/foo/bar#hey?beep=boop'\n//  }\n\nconst hashPatch = { hash: '#oh-no' }\nvar location = createLocation(location, hashPatch)\n// => {\n//    pathname: '/',\n//    hash: '#oh-no',\n//    search: { beep: 'boop' },\n//    href: '/foo/bar#oh-no?beep=boop'\n//  }\n\nconst uriPatch = '/hey/hello'\nvar location = createLocation(location, uriPatch)\n// => {\n//    pathname: '/hey/hello',\n//    hash: '',\n//    search: { },\n//    href: '/hey/hello'\n//  }\n```\n\n### virtual-dom example\n```js\nconst render = require('virtual-dom/create-element')\nconst sheetRouter = require('sheet-router')\nconst h = require('virtual-dom/h')\nconst hyperx = require('hyperx')\n\nconst html = hyperx(h)\n\nconst router = sheetRouter([\n  ['/foo/bar', (params, h, state) => html`<div>hello world!</div>`]\n])\n\nconst node = render(router('/foo/bar', h, { name: 'Jane' }))\ndocument.body.appendChild(node)\n```\n```html\n<body>\n  <div>hello world</div>\n</body>\n```\n\n### react example\n```js\nconst sheetRouter = require('sheet-router')\nconst render = require('react-dom')\nconst hyperx = require('hyperx')\nconst react = require('react')\n\nconst html = hyperx(react.createElement)\n\nconst router = sheetRouter([\n  ['/foo/bar', (params, h, state) => html`<div>hello world!</div>`]\n])\n\nrender(router('/foo', react.createElement, { name: 'Jane' }), document.body)\n```\n```html\n<body>\n  <div>hello world</div>\n</body>\n```\n\n## API\n### router = sheetRouter(opts?, [routes])\nCreate a new router from a nested array. Takes an optional options object as\nthe first argument. Options are:\n- __opts.default__: defaults to `'/404'`, default path to use if no paths match\n- __opts.thunk__: defaults to `true`. Toggle if callbacks should be thunked or\n  not. Can be set to `'match'` to only have the returned `router.match()`\n  function expect thunks to exist. Useful to write a custom `walk` function\n  that creates a different signature\n\n### router(path, [,...])\nMatch a route on the router. Takes a path and an arbitrary list of arguments\nthat are then passed to the matched routes. Cleans urls to only match the\n[pathname][15].\n\n### history(cb(href))\nCall a callback to handle html5 pushsState history.\n\n### href(cb(href))\nCall a callback to handle `<a href=\"#\">` clicks.\n\n## See Also\n- [wayfarer][12]\n- [hyperx][14]\n- [choo](https://github.com/yoshuawuyts/choo)\n\n## License\n[MIT](https://tldrlegal.com/license/mit-license)\n\n[mdn-qs]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search\n[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square\n[1]: https://nodejs.org/api/documentation.html#documentation_stability_index\n[2]: https://img.shields.io/npm/v/sheet-router.svg?style=flat-square\n[3]: https://npmjs.org/package/sheet-router\n[4]: https://img.shields.io/travis/yoshuawuyts/sheet-router/master.svg?style=flat-square\n[5]: https://travis-ci.org/yoshuawuyts/sheet-router\n[6]: https://img.shields.io/codecov/c/github/yoshuawuyts/sheet-router/master.svg?style=flat-square\n[7]: https://codecov.io/github/yoshuawuyts/sheet-router\n[8]: http://img.shields.io/npm/dm/sheet-router.svg?style=flat-square\n[9]: https://npmjs.org/package/sheet-router\n[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\n[11]: https://github.com/feross/standard\n[12]: https://github.com/yoshuawuyts/wayfarer\n[13]: https://github.com/Matt-Esch/virtual-dom\n[14]: https://github.com/substack/hyperx\n[15]: https://nodejs.org/api/url.html#url_url_parsing\n","maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"time":{"modified":"2022-06-12T14:49:03.977Z","created":"2017-03-02T14:58:04.974Z","4.2.4":"2017-03-02T14:58:04.974Z","4.2.5":"2017-03-02T16:13:46.663Z"},"homepage":"https://github.com/aknuds1/sheet-router#readme","keywords":["client","router","modular","wayfarer","history","pushstate","single-page","spa","progressive"],"repository":{"type":"git","url":"git+https://github.com/aknuds1/sheet-router.git"},"bugs":{"url":"https://github.com/aknuds1/sheet-router/issues"},"license":"MIT","readmeFilename":"README.md"}