/** * 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 { /** * A function for encoding input strings. */ encodePath?: Encode; } export interface PathToRegexpOptions { /** * Matches the path completely without trailing characters. (default: `true`) */ end?: boolean; /** * Allows optional trailing delimiter to match. (default: `true`) */ trailing?: boolean; /** * Match will be case sensitive. (default: `false`) */ sensitive?: boolean; /** * The default delimiter for segments. (default: `'/'`) */ delimiter?: string; } export interface MatchOptions extends PathToRegexpOptions { /** * Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`) */ decode?: Decode | false; } export interface CompileOptions { /** * Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`) */ encode?: Encode | false; /** * The default delimiter for segments. (default: `'/'`) */ delimiter?: string; } /** * Plain text. */ export interface Text { type: "text"; value: string; } /** * A parameter designed to match arbitrary text within a segment. */ export interface Parameter { type: "param"; name: string; } /** * A wildcard parameter designed to match multiple segments. */ export interface Wildcard { type: "wildcard"; name: string; } /** * A set of possible tokens to expand when matching. */ export interface Group { type: "group"; tokens: readonly Token[]; } /** * Tokens that corresponds with a regexp capture. */ export type Key = Parameter | Wildcard; /** * A sequence of path match characters. */ export type Token = Text | Parameter | Wildcard | Group; /** * Tokenized path instance. */ export interface TokenData { tokens: readonly Token[]; originalPath?: string; } /** * ParseError is thrown when there is an error processing the path. */ export declare class PathError extends TypeError { readonly originalPath: string | undefined; constructor(message: string, originalPath: string | undefined); } /** * 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 & ParseOptions): (params?: P) => string;
export type ParamData = Partial = (data?: P) => string;
/**
* A match result contains data about the path match.
*/
export interface MatchResult {
path: string;
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 ;
/**
* Supported path inputs.
*/
export type Path = string | TokenData;
/**
* Transform a path into a match function.
*/
export declare function match (path: Path | Path[], options?: MatchOptions & ParseOptions): MatchFunction ;
/**
* Transform a path into a regular expression and capture keys.
*/
export declare function pathToRegexp(path: Path | Path[], options?: PathToRegexpOptions & ParseOptions): {
regexp: RegExp;
keys: Key[];
};
/**
* Stringify token data into a path string.
*/
export declare function stringify(data: TokenData): string;