5.0.1 • Published 5 years ago

dfa-router v5.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

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.

5.0.1

5 years ago

5.0.0

5 years ago

4.0.0

6 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago