import { match, pathToRegexp, compile, parse, stringify } from "path-to-regexp";
Parameters
Parameters match arbitrary strings in a path by matching up to the end of the segment, or up to any proceeding tokens. They are defined by prefixing a colon to the parameter name (:foo). Parameter names can use any valid JavaScript identifier, or be double quoted to use other characters (:"param-name").
Wildcard parameters match one or more characters across multiple segments. They are defined the same way as regular parameters, but are prefixed with an asterisk (*foo).
decode Function for decoding strings to params, or false to disable all processing. (default: decodeURIComponent)
const fn = match("/foo/:bar");
Please note:path-to-regexp is intended for ordered data (e.g. paths, hosts). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc).
PathToRegexp
The pathToRegexp function returns the regexp for matching strings against paths, and an array of keys for understanding the RegExp#exec matches.
path String, TokenData object, or array of strings and TokenData objects.
An effort has been made to ensure ambiguous paths from previous releases throw an error. This means you might be seeing an error when things worked before.
Missing parameter name
Parameter names must be provided after : or *, for example /*path. They can be valid JavaScript identifiers (e.g. :myName) or JSON strings (:"my-name").
Unexpected ? or +
In past releases, ?, *, and + were used to denote optional or repeating parameters. As an alternative, try these:
For optional (?), use braces: /file{.:ext}.
For one or more (+), use a wildcard: /*path.
For zero or more (*), use both: /files{/*path}.
Unexpected (, ), [, ], etc.
Previous versions of Path-to-RegExp used these for RegExp features. This version no longer supports them so they've been reserved to avoid ambiguity. To match these characters literally, escape them with a backslash, e.g. "\\(".
Unterminated quote
Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character. For example, :"foo.
Express <= 4.x
Path-To-RegExp breaks compatibility with Express <= 4.x in the following ways:
The wildcard * must have a name and matches the behavior of parameters :.
The optional character ? is no longer supported, use braces instead: /:file{.:ext}.
Regexp characters are not supported.
Some characters have been reserved to avoid confusion during upgrade (()[]?+!).
Parameter names now support valid JavaScript identifiers, or quoted like :"this".