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

multi-path-matcher

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multi-path-matcher

finds and decodes best matching path in a set of routes

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
644
decreased by-36.11%
Maintainers
1
Weekly downloads
 
Created
Source

npm Greenkeeper semantic-release styled with prettier Build Status codecov.io Known Vulnerabilities GitHub Issues Dependency Status devDependency Status docs downloads Commitizen friendly

multi-path-matcher

finds and decodes best matching path in a set of routes

usage

With paramus

import { compile, matcher } from "multi-path-matcher";

const routes = [
  { path: "/a/b/c" },
  { path: "/a/b" },
  { path: "/d/:att1/e/:att2" },
  { path: "/d/:att1/e" },
  { path: "/" }
];

const compiled = compile(routes);

matcher(compiled "/a");                   // undefined
matcher(compiled, "/a/b");                // routes[1]
matcher(compiled, "/a/b/c");              // routes[0]
matcher(compiled, "/d/value1/e");         // routes[3] { att1: "value1" }
matcher(compiled, "/d/value1/e/value2");  // routes[2] { att1: "value1", att2: "value2" }
matcher(compiled, "/");                   // routes[4]

With wildcards

import { compile, matcher } from "multi-path-matcher";

const routes = [
  { path: "/" },
  { path: "/*" },
  { path: "/about"},
  { path: "/login" }
];

const compiled = compile(routes);

matcher(compiled "/");                   // routes[0]
matcher(compiled "/index.html");         // routes[1]
matcher(compiled "/about");              // routes[2]
matcher(compiled "/login");              // routes[3]

API

Table of Contents

CompiledRoutes

Result of the routes compilation

Type: Object

Parameters

Route

One single route

Type: Object

Properties

Match

result of a match

Type: Object

Properties

  • route Route as given to the compiler
  • params Object extracted from the path

compile

Compile a set of routes

Parameters

Returns CompiledRoutes

CompiledRoute

Result of a path compilation priorities for each path component

  • :param -> 0
  • match * or ? -> 1
  • plain -> 2

Type: Object

Properties

  • regex RegExp for later checking and params extration
  • keys Set<string> all keys found in the route
  • priority number order in which to check

pathToRegexp

Generate regex with priority

Parameters

Returns CompiledRoute

matcher

Find best match for a given path

Parameters

Returns Match match

install

With npm do:

npm install multi-path-matcher

license

BSD-2-Clause

Keywords

FAQs

Package last updated on 10 Aug 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