{"_id":"@altrdpdgm/router","_rev":"1-96a22bb3ca10ed7282006fe417b0dcf9","name":"@altrdpdgm/router","description":"A JavaScript routing module.","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@altrdpdgm/router","version":"2.0.0","description":"A JavaScript routing module.","main":"","author":{"name":"Sean T Taylor"},"repository":{"type":"git","url":"git+https://github.com/seanttaylor/altrd-router.git"},"bugs":{"url":"https://github.com/seanttaylor/altrd-router/issues","email":"altrdpgdm@gmail.com"},"license":"ISC","dependencies":{},"devDependencies":{},"gitHead":"f37f13ba6e62f3e637503fc0d492c7a4e730b8d5","homepage":"https://github.com/seanttaylor/altrd-router#readme","_id":"@altrdpdgm/router@2.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"altrdpdgm","email":"altrdpdgm@gmail.com"},"dist":{"integrity":"sha512-kO3U8y3Tk0AuI+cVhJ+8st1jPyMopYbY71rVbOcGNNI8AUU45RrpluTx234fK5AQ+JTzkK93hUbB4Qr6ERkgnA==","shasum":"8b90d76c7cce82ba243915c18c4ad0da2ff94c00","tarball":"https://registry.npmjs.org/@altrdpdgm/router/-/router-2.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBAguof9s9RZ6fPRqkCOHwETRC51pRtVUSUsaABB4i5TAiEA59cm1iULEItl+9cQbTJCAFXA9H22oHP4sNDl9VNJ7fk="}]},"maintainers":[{"name":"altrdpdgm","email":"altrdpdgm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/router-2.0.0.tgz_1515978083068_0.6309667897876352"}}},"readme":"## altrd-router\nA JavaScript routing module.\n\naltrd-router is a lighweight vanilla JavaScript client-side router for single page applications. It is a refinement on Joakim Carlstein's proof of concept for a 20-line JavaScript router documented [here](http://joakim.beng.se/blog/posts/a-javascript-router-in-20-lines.html).\n\nThis module supports basic client-side routing that is drive by plain JavaScript and can work with any view library or templating language.\n\n### Modules\n\naltrd-router consists of (2) modules: Router and RouteTable.\n\n#### Router\n\nRouter houses all business logic of the router via hash-based routing. `Router()` takes an object with optional arguments and returns an instance of `Router` that exposes a `start` and a `RouteTable` method.\n\n|function/method | description |\n|---|---|\n| validateRoute | *private* function, checks for presence of a given URL on `Router`'s internal `routeMap`. On `undefined` route, returns `false` |\n|regRoute| *private* function, adds an argument `route` to `Router`'s internal `routeMap` | \n|resolveRoute| *private* function, resolves any route that has a `resolve` method. Resolve methods are functions that request some async data and return promise. Takes a `route`, a `params` object containing query parameters in the URL being triggered and a `routeTimer`.|\n|execRoute | *private* function, clears `routeTimer`, if still in effect, initializes route controller with any data returned from `resolveRoute`.|\n|router| *private* function, triggered on `Window`'s `load` or `hashchange` event, takes a URL string, starts `routeTimer` used to trigger a loading animation, starts route validation.|\n|getParams| *private* function, takes a `URL` and returns an object mapping `URL` query parameters to their values. |\n|stripParams| *private* function, takes `URL` and removes any query params, returning only the stripped URL.|\n|start| registers all routes, adds event listeners for the `load`and `hashchange` events. Takes a `routeTable` and callback to trigger after route registration.| \n|RouteTable| a constructor returning and instance of `RouteTable`. See list of methods available on this constructor below.|\n\n#### RouteTable\n\nRouteTable stores route objects and exposes (2) methods: `addRoute` and `routes`.\n\n|function/method | description |\n|---| ---|\n|addRoute| adds a route object to an internal `routeTable` array.|\n|routes| returns internal `routeTable`. An array of all registered routes. |\n\n### The Route object\n\nRoutes are plain JavaScript objects with the following fields:\n\n|field| description| \n|---|---|\n|path| [*required*] __string__ with a leading backslash and *without* `#` sign. This is the URL that will trigger the route (e.g. `https://mysite.com/index#/list`)|\n|templateURL| __string__ file path to the template to be loaded in the view.\n|controller| __function__ manages all data and events for a specified view. |\n|container | __string__ a querySelector to identify the dom node to attach the rendered template to (e.g. `#container`.) |\n|resolve| __function__ returns a `Promise`. Used to delay loading a view until async data is fetched. |\n|onTimeout| __function__ executes after the `timeout` duration has been reached. Usually used to show a loading animation on routes that require data fetched from the server.| \n|timeout| __integer__ a value in milliseconds to wait before calling the `onTimeout` method.|\n\n\n\n","maintainers":[{"name":"altrdpdgm","email":"altrdpdgm@gmail.com"}],"time":{"modified":"2022-04-04T13:40:38.342Z","created":"2018-01-15T01:01:24.012Z","2.0.0":"2018-01-15T01:01:24.012Z"},"homepage":"https://github.com/seanttaylor/altrd-router#readme","repository":{"type":"git","url":"git+https://github.com/seanttaylor/altrd-router.git"},"author":{"name":"Sean T Taylor"},"bugs":{"url":"https://github.com/seanttaylor/altrd-router/issues","email":"altrdpgdm@gmail.com"},"license":"ISC","readmeFilename":"README.md"}