path-to-regexp
- Version 8.2.0
- Published
- 55.2 kB
- No dependencies
- MIT license
Install
npm i path-to-regexp
yarn add path-to-regexp
pnpm add path-to-regexp
Overview
Express style path to RegExp utility
Index
Functions
Classes
Interfaces
Type Aliases
Functions
function compile
compile: < P extends Partial<Record<string, string | string[]>> = Partial< Record<string, string | string[]> >>( path: Path, options?: CompileOptions & ParseOptions) => (data?: P) => string;
Compile a string to a template function for the path.
function match
match: <P extends Partial<Record<string, string | string[]>>>( path: Path | Path[], options?: MatchOptions & ParseOptions) => MatchFunction<P>;
Transform a path into a match function.
function parse
parse: (str: string, options?: ParseOptions) => TokenData;
Parse a string for the raw tokens.
function pathToRegexp
pathToRegexp: ( path: Path | Path[], options?: PathToRegexpOptions & ParseOptions) => { regexp: RegExp; keys: Keys };
function stringify
stringify: (data: TokenData) => string;
Stringify token data into a path string.
Classes
class TokenData
class TokenData {}
Tokenized path instance.
constructor
constructor(tokens: Token[]);
property tokens
readonly tokens: Token[];
Interfaces
interface CompileOptions
interface CompileOptions {}
interface Group
interface Group {}
A set of possible tokens to expand when matching.
interface MatchOptions
interface MatchOptions extends PathToRegexpOptions {}
property decode
decode?: Decode | false;
Function for decoding strings for params, or
false
to disable entirely. (default:decodeURIComponent
)
interface MatchResult
interface MatchResult<P extends ParamData> {}
A match result contains data about the path match.
interface Parameter
interface Parameter {}
A parameter designed to match arbitrary text within a segment.
interface ParseOptions
interface ParseOptions {}
property encodePath
encodePath?: Encode;
A function for encoding input strings.
interface PathToRegexpOptions
interface PathToRegexpOptions {}
property delimiter
delimiter?: string;
The default delimiter for segments. (default:
'/'
)
property end
end?: boolean;
Matches the path completely without trailing characters. (default:
true
)
property sensitive
sensitive?: boolean;
Match will be case sensitive. (default:
false
)
property trailing
trailing?: boolean;
Allows optional trailing delimiter to match. (default:
true
)
Type Aliases
type Decode
type Decode = (value: string) => string;
Decode a string into another string.
type Encode
type Encode = (value: string) => string;
Encode a string into another string.
type Key
type Key = Parameter | Wildcard;
A token that corresponds with a regexp capture.
type Keys
type Keys = Array<Key>;
A sequence of
path-to-regexp
keys that match capturing groups.
type Match
type Match<P extends ParamData> = false | MatchResult<P>;
A match is either
false
(no match) or a match result.
type MatchFunction
type MatchFunction<P extends ParamData> = (path: string) => Match<P>;
The match function takes a string and returns whether it matched the path.
type ParamData
type ParamData = Partial<Record<string, string | string[]>>;
type Path
type Path = string | TokenData;
Supported path types.
type PathFunction
type PathFunction<P extends ParamData> = (data?: P) => string;
type Token
type Token = Text | Parameter | Wildcard | Group;
A sequence of path match characters.
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (8)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/path-to-regexp
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/path-to-regexp)
- HTML<a href="https://www.jsdocs.io/package/path-to-regexp"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3917 ms. - Missing or incorrect documentation? Open an issue for this package.