New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

route-match

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-match

Can be used to match and generate url paths agains predefined patterns. Can be used when applying routing in javascript client-side and backend applications. Uses ECMA6 javascript standard.

  • 0.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
63
increased by96.88%
Maintainers
1
Weekly downloads
 
Created
Source

route-match

NPM package that can be used to match and generate url paths agains predefined patterns. Can be used when applying routing in javascript client-side and backend applications. Uses ECMA6 javascript standard.

Installation

npm install --save route-match

Usage

When using a client that does not support ECMA6, please use a javascript compiler like Babel to compile the code to a readable format.

Generating URLs

import { Route, RouteCollection, PathGenerator } from 'route-match';

var myRouteCollection = new RouteCollection([
    new Route('user_detail', '/user/:id(\\d+)')
]);

var myPathGenerator = new PathGenerator(myRouteCollection);

console.log(myPathGenerator.generate('user_detail', { id: 10 })); // result: /user/10

Remarks:

  • when you supply more parameters then the route pattern requires, the extra parameters are added to the generated url as query parameters
  • when you supply parameters that do not match the requirements an error will be thrown
  • Feel free to use non-ECMA6 syntax

Matching urls against patterns

import { Route, RouteCollection, PathMatcher } from 'route-match';

var myRouteCollection = new RouteCollection([
    new Route('user_detail', '/user/:id(\\d+)')
]);

var myPathMatcher = new PathMatcher(myRouteCollection);

console.log(myPathGenerator.match('/user/10'); // result: instance of RouteMatch containing route name, payload and parameters 

Remarks:

  • When the supplied url contains query parameters, they will also be available in the eventual RouteMatch object
  • When no route is matched, null is returned
  • Feel free to use non-ECMA6 syntax

Running unit tests

npm test

Compiling ECMA6 code to 'regular' javascript

npm run compile

Keywords

FAQs

Package last updated on 04 Nov 2015

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