0.2.0 • Published 5 years ago

@yagni-js/yagni-router v0.2.0

Weekly downloads
-
License
Unlicense
Repository
github
Last release
5 years ago

yagni-router

Yet another pure functional router for browser.

Pure functional in this context means functional code style - library code is linted using eslint-plugin-fp and eslint-plugin-better. Javascript code of the library is purely functional.

Source code is written using ES6 modules, built using rollup and distributed in two formats - as CommonJS module and as ES6 module.

Features

Currently supports hash-based routing only.

Installation

Using npm:

$ npm install --save-dev @yagni-js/yagni @yagni-js/yagni-dom @yagni-js/yagni-router

Using yarn:

$ yarn add -D @yagni-js/yagni @yagni-js/yagni-dom @yagni-js/yagni-router

Usage

CommonJS usage:

const url = require('@yagni-js/yagni-router').url;
const hashRouter = require('@yagni-js/yagni-router').hashRouter;

ES6 module usage:

import { url, hashRouter } from '@yagni-js/yagni-parser';

Documentation

Not yet available, please check sources.

Example

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);

License

Unlicense