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

radix-router

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

radix-router

Radix tree based router

  • 0.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18K
decreased by-19.15%
Maintainers
1
Weekly downloads
 
Created
Source

Radix Router

Build Status

A router implemented using a Radix Tree (aka compact Prefix Tree). This router has support for placeholders and wildcards.

Installation

npm install --save radix-router

better yet

yarn add radix-router

Usage

insert(path, data) - adds the given path to the router and associates the given data with the path

lookup(path) - performs a lookup of the path. If there is a match, the data associated with the route is returned

delete(path) - deletes the path from the router

startsWith(prefix) - returns a map of all routes starting with the given prefix and the data associated with them

Example

const RadixRouter = require('radix-router');

let router = new RadixRouter();

router.insert('/api/v1/route', {
    much: 'data'
});

router.insert('/api/v2/**', {
    such: 'wildcard'
});

router.insert('/api/v1/other-route/:id', {
    so: 'placeholder',
    much: 'wow'
});

router.lookup('/api/v1/route');
// returns {
//     path: '/api/v1/route',
//     data: {
//         much: 'data'
//     }
// }

router.lookup('/api/v2/anything/goes/here');
// returns {
//     path: '/api/v2/cool',
//     data: {
//         such: 'wildcard'
//     }
// }

router.lookup('/api/v1/other-route/abcd');
// returns {
//     path: '/api/v1/other-route/abcd',
//     data: {
//         so: 'placeholder',
//         much: 'wow'
//     },
//     params: {
//         id: 'abcd'
//     }
// }

// remove route
router.delete('/api/v2/**');

router.lookup('/api/v2/anything/goes/here');
// returns {
//     path: '/api/v2/cool',
//     data: null
// }

route.startsWith('/api')
// returns {
//     '/api/v1/route': {
//         much: 'data'
//     },
//     '/api/v1/other-route/:id': {
//         so: 'placeholder',
//         much: 'wow'
//     }
// }

FAQs

Package last updated on 08 Nov 2016

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