Skip to content
A simple server-side url router using Deterministic Finite Automaton.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples add examples Oct 28, 2016
test return params as a Map Nov 13, 2016
.babelrc first commit Oct 28, 2016
.gitignore release v1.0.1 Oct 28, 2016
.npmignore add examples Oct 28, 2016
README.md make README follow new interface Nov 13, 2016
circle.yml collect coverage Oct 28, 2016
dfa_table.ts
index.ts change exported interface Oct 28, 2016
package.json return params as a Map Nov 13, 2016
router.ts first commit Oct 28, 2016
tsconfig.json first commit Oct 28, 2016
tslint.json first commit Oct 28, 2016

README.md

dfa-router

CircleCI Codecov

A simple server-side url router using Deterministic Finite Automaton.

Installation

This is published at npm registry: dfa-router.

You can install it via npm, yarn or what you like.

npm install dfa-router

How to Use

It behaves like a simple key-value map.

const router = new Router();
router.add('GET', '/foo', 'foo');
router.add('GET', '/bar', 'bar');

const foo = router.route('GET', '/foo');
assert.deepEqual(foo, {
  type: 'found',
  value: 'foo',
  params: new Map([]),
});
const bar = router.route('GET', '/bar');
assert.deepEqual(bar, {
  type: 'found',
  value: 'bar',
  params: new Map([]),
});

And also, it can capture parameters.

const router = new Router();
router.add('GET', '/:param', 'foo');

const foo = router.route('GET', '/value');
assert.deepEqual(foo, {
  type: 'found',
  value: 'foo',
  params: new Map([
    ['param', 'value']
  ]),,
});

See examples/server.js and test/ to learn more.

You can’t perform that action at this time.