Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dfa-router

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dfa-router

[![CircleCI](https://img.shields.io/circleci/project/github/KOBA789/dfa-router.svg?style=flat-square)](https://circleci.com/gh/KOBA789/dfa-router) [![Codecov](https://img.shields.io/codecov/c/github/KOBA789/dfa-router.svg?style=flat-square)](https://codec

  • 5.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 14 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc