/** * Encode a string into another string. */ export type Encode = (value: string) => string; /** * Decode a string into another string. */ export type Decode = (value: string) => string; export interface ParseOptions { /** * The default delimiter for segments. (default: `'/'`) */ delimiter?: string; /** * A function for encoding input strings. */ encodePath?: Encode; } export interface PathToRegexpOptions extends ParseOptions { /** * Regexp will be case sensitive. (default: `false`) */ sensitive?: boolean; /** * Allow the delimiter to be arbitrarily repeated. (default: `true`) */ loose?: boolean; /** * Verify patterns are valid and safe to use. (default: `false`) */ strict?: boolean; /** * Match from the beginning of the string. (default: `true`) */ start?: boolean; /** * Match to the end of the string. (default: `true`) */ end?: boolean; /** * Allow optional trailing delimiter to match. (default: `true`) */ trailing?: boolean; } export interface MatchOptions extends PathToRegexpOptions { /** * Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`) */ decode?: Decode | false; } export interface CompileOptions extends ParseOptions { /** * Regexp will be case sensitive. (default: `false`) */ sensitive?: boolean; /** * Allow the delimiter to be arbitrarily repeated. (default: `true`) */ loose?: boolean; /** * Verify patterns are valid and safe to use. (default: `false`) */ strict?: boolean; /** * Verifies the function is producing a valid path. (default: `true`) */ validate?: boolean; /** * Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`) */ encode?: Encode | false; } /** * Tokenized path instance. Can we passed around instead of string. */ export declare class TokenData { readonly tokens: Token[]; readonly delimiter: string; constructor(tokens: Token[], delimiter: string); } /** * Parse a string for the raw tokens. */ export declare function parse(str: string, options?: ParseOptions): TokenData; /** * Compile a string to a template function for the path. */ export declare function compile
(path: Path, options?: CompileOptions): PathFunction
;
export type ParamData = Partial = (data?: P) => string;
/**
* A match result contains data about the path match.
*/
export interface MatchResult {
path: string;
index: number;
params: P;
}
/**
* A match is either `false` (no match) or a match result.
*/
export type Match = false | MatchResult ;
/**
* The match function takes a string and returns whether it matched the path.
*/
export type MatchFunction = (path: string) => Match ;
/**
* Create path match function from `path-to-regexp` spec.
*/
export declare function match (path: Path, options?: MatchOptions): MatchFunction ;
/**
* A key is a capture group in the regex.
*/
export interface Key {
name: string;
prefix?: string;
suffix?: string;
pattern?: string;
modifier?: string;
separator?: string;
}
/**
* A token is a string (nothing special) or key metadata (capture group).
*/
export type Token = string | Key;
/**
* Repeated and simple input types.
*/
export type Path = string | TokenData;
/**
* 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 }]`.
*/
export declare function pathToRegexp(path: Path, options?: PathToRegexpOptions): RegExp & {
keys: Key[];
};