@yagni-js/yagni-router
Version:
yagni-js router
102 lines (55 loc) • 1.75 kB
Markdown
Yet another **pure functional** router for browser.
**Pure functional** in this context means functional code style - library code is
linted using [eslint-plugin-fp][eslint-plugin-fp] and
[][eslint-plugin-better]. Javascript code of the library is
purely functional.
Source code is written using [ES6 modules][es6-modules], built using
[][rollup] and distributed in two formats - as CommonJS module and as
ES6 module.
Currently supports hash-based routing only.
Using `npm`:
```shell
$ npm install --save-dev @yagni-js/yagni @yagni-js/yagni-dom @yagni-js/yagni-router
```
Using `yarn`:
```shell
$ yarn add -D @yagni-js/yagni @yagni-js/yagni-dom @yagni-js/yagni-router
```
CommonJS usage:
```javascript
const url = require('@yagni-js/yagni-router').url;
const hashRouter = require('@yagni-js/yagni-router').hashRouter;
```
ES6 module usage:
```javascript
import { url, hashRouter } from '@yagni-js/yagni-parser';
```
Not yet available, please check sources.
```javascript
import { url, hashRouter } from '@yagni-js/yagni-parser';
function fooHandler(match) {
// ...
}
function bazHandler(match) {
// ...
}
const routes = [
url(/^foo/, fooHandler),
url(/^baz\/\d+$/, bazHandler)
];
const router = hashRouter(routes);
window.addEventListener('hashchange', router, false);
```
[][unlicense]
[]: https://github.com/jfmengels/eslint-plugin-fp
[]: https://github.com/idmitriev/eslint-plugin-better
[]: https://hacks.mozilla.org/2015/08/es6-in-depth-modules/
[]: https://rollupjs.org/
[]: http://unlicense.org/