4.1.1 • Published 3 months ago

multi-path-matcher v4.1.1

Weekly downloads
1,017
License
BSD-2-Clause
Repository
github
Last release
3 months ago

npm License Typed with TypeScript bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status

multi-path-matcher

Finds and decodes best matching path in a set of routes

usage

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]

API

Table of Contents

Route

One single route

Type: Object

Properties

CompiledRoute

Result of a path compilation priorities for each path component

Type: Route

Properties

Match

Result of a match

Type: Object

Properties

  • route Route? as given to the compiler, undefined if no matching route was found
  • params Object extracted from the path

PLAIN

Prioritiy for a plain path component

Type: number

WILDCARD

Prioritiy for a path component with a wildcard '*'

Type: number

PARAM

Prioritiy for a parameter path component

Type: number

compile

Compile a set of routes. All properties of the original routes are preserved

Parameters

Returns Array<CompiledRoute>

pathToRegexp

Generate regex with priority.

Parameters

Returns CompiledRoute

matcher

Find best match for a given path. Decodes params into an object.

Parameters

Returns Match match

install

With npm do:

npm install multi-path-matcher

license

BSD-2-Clause

4.1.1

3 months ago

4.1.0

3 months ago

4.0.0

3 months ago

3.0.1

7 months ago

3.0.0

7 months ago

2.3.3

12 months ago

2.3.2

1 year ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.14

2 years ago

2.1.12

2 years ago

2.1.13

2 years ago

2.1.11

2 years ago

2.1.10

2 years ago

2.1.9

2 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.4

3 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.15

4 years ago

2.0.13

4 years ago

2.0.14

4 years ago

2.0.12

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago