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");
matcher(compiled, "/a/b");
matcher(compiled, "/a/b/c");
matcher(compiled, "/d/value1/e");
matcher(compiled, "/d/value1/e/value2");
matcher(compiled, "/");
With wildcards
import { compile, matcher } from "multi-path-matcher";
const routes = [
{ path: "/" },
{ path: "/*" },
{ path: "/about"},
{ path: "/login" }
];
const compiled = compile(routes);
matcher(compiled "/");
matcher(compiled "/index.html");
matcher(compiled "/about");
matcher(compiled "/login");
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 compilerparams
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 extrationkeys
Set<string> all keys found in the routepriority
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