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

route-recognizer

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-recognizer

A lightweight JavaScript library that matches paths against registered routes.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
482K
decreased by-13.64%
Maintainers
2
Weekly downloads
 
Created

What is route-recognizer?

The route-recognizer npm package is a lightweight JavaScript library for recognizing and handling URL routes. It is commonly used in client-side applications to manage navigation and routing, allowing developers to map URLs to specific handlers or actions.

What are route-recognizer's main functionalities?

Adding Routes

This feature allows you to add routes to the router. In the code sample, a route is added that matches URLs of the form '/posts/:id' and associates them with a handler named 'postHandler'. The recognize method is then used to match a URL against the added routes.

const RouteRecognizer = require('route-recognizer');
const router = new RouteRecognizer();

router.add([{ path: '/posts/:id', handler: 'postHandler' }]);
console.log(router.recognize('/posts/123'));

Recognizing Routes

This feature allows you to recognize and extract parameters from URLs. In the code sample, a route is added that matches URLs of the form '/users/:userId'. The recognize method is used to match a URL and extract the userId parameter.

const RouteRecognizer = require('route-recognizer');
const router = new RouteRecognizer();

router.add([{ path: '/users/:userId', handler: 'userHandler' }]);
const result = router.recognize('/users/42');
console.log(result[0].handler); // 'userHandler'
console.log(result[0].params); // { userId: '42' }

Generating URLs

This feature allows you to generate URLs from route names and parameters. In the code sample, a route is added with a name 'product'. The generate method is used to create a URL for the route by providing the necessary parameters.

const RouteRecognizer = require('route-recognizer');
const router = new RouteRecognizer();

router.add([{ path: '/products/:productId', handler: 'productHandler', name: 'product' }]);
const url = router.generate('product', { productId: '567' });
console.log(url); // '/products/567'

Other packages similar to route-recognizer

FAQs

Package last updated on 28 Jun 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