
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
multi-path-matcher
Advanced tools
Finds and decodes best matching path in a set of routes
With params
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?sort=asc"); // 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?param=1"); // routes[3]
One single route
Type: Object
path
string Result of a path compilation priorities for each path component
Type: Route
regex
RegExp for later checking and params extractionkeys
Array<string> all keys found in the routepriority
number order in which to checkResult of a match
Type: Object
route
Route? as given to the compiler, undefined if no matching route was foundparams
Object extracted from the pathPrioritiy for a plain path component
Type: number
Prioritiy for a path component with a wildcard '*'
Type: number
Prioritiy for a parameter path component
Type: number
Compile a set of routes. All properties of the original routes are preserved
Returns Array<CompiledRoute>
Generate regex with priority.
route
Route Returns CompiledRoute
Find best match for a given path. Decodes params into an object.
compiled
Array<CompiledRoute> path
string Returns Match match
With npm do:
npm install multi-path-matcher
BSD-2-Clause
FAQs
Finds and decodes best matching path in a set of routes
The npm package multi-path-matcher receives a total of 1,459 weekly downloads. As such, multi-path-matcher popularity was classified as popular.
We found that multi-path-matcher demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.