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

radix3

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

radix3

Lightweight and fast router for JavaScript based on Radix Tree

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
decreased by-2.52%
Maintainers
1
Weekly downloads
 
Created
Source

🌳 radix3

npm version npm downloads Github Actions Codecov bundle

Lightweight and fast router for JavaScript based on Radix Tree.

Usage

Install package:

# npm
npm install radix3

# yarn
yarn add radix3

Import:

// ESM
import { createRouter } from 'radix3'

// CJS
const { createRouter } = require('radix3')

Create a router instance and insert routes:

const router = createRouter()

router.insert('/path', { payload: 'this path' })
router.insert('/path/:name', { payload: 'named route' })
router.insert('/path/foo/**', { payload: 'wildcard route' })

*Match route to access matched data:

// { payload: 'this path' }
router.lookup('/path')

// { payload: 'named route', params: { name: 'fooval' } }
router.lookup('/path/fooval')

// { payload: 'wildcard route' }
router.lookup('/path/foo/bar/baz')

// null (no route matched for/)
router.lookup('/')

Methods

router.insert(path, data)

path can be static or using :placeholders and ** for wildcard paths.

The data object will be returned on matching params. It should be an object like { handler } and not containing reserved keyword params.

router.lookup(path)

Returns matched data for path with optional params key if mached route using placeholders.

router.lookupAll(prefix)

Find all data nodes matching path prefix.

router.remove(path)

Remove route matching path.

Performance

See benchmark.

License

Based on original work of charlieduong94/radix-router by Charlie Duong (MIT)

MIT - Made with ❤️

FAQs

Package last updated on 09 Mar 2022

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