path-to-regexp
- Version 7.1.0
- Published
- 65 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) => PathFunction<P>;
Compile a string to a template function for the path.
function match
match: <P extends Partial<Record<string, string | string[]>>>( path: Path, options?: MatchOptions) => MatchFunction<P>;
Create path match function from
path-to-regexp
spec.
function parse
parse: (str: string, options?: ParseOptions) => TokenData;
Parse a string for the raw tokens.
function pathToRegexp
pathToRegexp: ( path: Path, options?: PathToRegexpOptions) => RegExp & { keys: Key[] };
Normalize the given path string, returning a regular expression.
An empty array can be passed in for the keys, which will hold the placeholder key descriptions. For example, using
/user/:id
,keys
will contain[{ name: 'id', delimiter: '/', optional: false, repeat: false }]
.
Classes
class TokenData
class TokenData {}
Tokenized path instance. Can we passed around instead of string.
constructor
constructor(tokens: Token[], delimiter: string);
property delimiter
readonly delimiter: string;
property tokens
readonly tokens: Token[];
Interfaces
interface CompileOptions
interface CompileOptions extends ParseOptions {}
property encode
encode?: Encode | false;
Function for encoding input strings for output into the path, or
false
to disable entirely. (default:encodeURIComponent
)
property loose
loose?: boolean;
Allow the delimiter to be arbitrarily repeated. (default:
true
)
property sensitive
sensitive?: boolean;
Regexp will be case sensitive. (default:
false
)
property strict
strict?: boolean;
Verify patterns are valid and safe to use. (default:
false
)
property validate
validate?: boolean;
Verifies the function is producing a valid path. (default:
true
)
interface Key
interface Key {}
A key is a capture group in the regex.
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 ParseOptions
interface ParseOptions {}
property delimiter
delimiter?: string;
The default delimiter for segments. (default:
'/'
)
property encodePath
encodePath?: Encode;
A function for encoding input strings.
interface PathToRegexpOptions
interface PathToRegexpOptions extends ParseOptions {}
property end
end?: boolean;
Match to the end of the string. (default:
true
)
property loose
loose?: boolean;
Allow the delimiter to be arbitrarily repeated. (default:
true
)
property sensitive
sensitive?: boolean;
Regexp will be case sensitive. (default:
false
)
property start
start?: boolean;
Match from the beginning of the string. (default:
true
)
property strict
strict?: boolean;
Verify patterns are valid and safe to use. (default:
false
)
property trailing
trailing?: boolean;
Allow 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 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;
Repeated and simple input types.
type PathFunction
type PathFunction<P extends ParamData> = (data?: P) => string;
type Token
type Token = string | Key;
A token is a string (nothing special) or key metadata (capture group).
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 3912 ms. - Missing or incorrect documentation? Open an issue for this package.