2024-10-14 06:09:33 +00:00
|
|
|
declare function pathToRegexp (path: pathToRegexp.Path, keys?: pathToRegexp.Key[], options?: pathToRegexp.RegExpOptions & pathToRegexp.ParseOptions): RegExp;
|
|
|
|
|
|
|
|
declare namespace pathToRegexp {
|
|
|
|
export interface RegExpOptions {
|
|
|
|
/**
|
2024-10-16 10:43:44 +00:00
|
|
|
* When `true` the route will be case sensitive. (default: `false`)
|
2024-10-14 06:09:33 +00:00
|
|
|
*/
|
|
|
|
sensitive?: boolean;
|
|
|
|
/**
|
2024-10-16 10:43:44 +00:00
|
|
|
* When `false` the trailing slash is optional. (default: `false`)
|
2024-10-14 06:09:33 +00:00
|
|
|
*/
|
|
|
|
strict?: boolean;
|
|
|
|
/**
|
2024-10-16 10:43:44 +00:00
|
|
|
* When `false` the path will match at the beginning. (default: `true`)
|
2024-10-14 06:09:33 +00:00
|
|
|
*/
|
|
|
|
end?: boolean;
|
|
|
|
/**
|
|
|
|
* Sets the final character for non-ending optimistic matches. (default: `/`)
|
|
|
|
*/
|
|
|
|
delimiter?: string;
|
|
|
|
/**
|
|
|
|
* List of characters that can also be "end" characters.
|
|
|
|
*/
|
|
|
|
endsWith?: string | string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ParseOptions {
|
|
|
|
/**
|
|
|
|
* Set the default delimiter for repeat parameters. (default: `'/'`)
|
|
|
|
*/
|
|
|
|
delimiter?: string;
|
|
|
|
/**
|
2024-10-16 10:43:44 +00:00
|
|
|
* List of valid delimiter characters. (default: `'./'`)
|
2024-10-14 06:09:33 +00:00
|
|
|
*/
|
2024-10-16 10:43:44 +00:00
|
|
|
delimiters?: string | string[];
|
2024-10-14 06:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse an Express-style path into an array of tokens.
|
|
|
|
*/
|
|
|
|
export function parse (path: string, options?: ParseOptions): Token[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforming an Express-style path into a valid path.
|
|
|
|
*/
|
2024-10-16 10:43:44 +00:00
|
|
|
export function compile (path: string, options?: ParseOptions): PathFunction;
|
2024-10-14 06:09:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform an array of tokens into a path generator function.
|
|
|
|
*/
|
2024-10-16 10:43:44 +00:00
|
|
|
export function tokensToFunction (tokens: Token[]): PathFunction;
|
2024-10-14 06:09:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform an array of tokens into a matching regular expression.
|
|
|
|
*/
|
|
|
|
export function tokensToRegExp (tokens: Token[], keys?: Key[], options?: RegExpOptions): RegExp;
|
|
|
|
|
|
|
|
export interface Key {
|
|
|
|
name: string | number;
|
|
|
|
prefix: string;
|
|
|
|
delimiter: string;
|
|
|
|
optional: boolean;
|
|
|
|
repeat: boolean;
|
|
|
|
pattern: string;
|
2024-10-16 10:43:44 +00:00
|
|
|
partial: boolean;
|
2024-10-14 06:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface PathFunctionOptions {
|
|
|
|
/**
|
|
|
|
* Function for encoding input strings for output.
|
|
|
|
*/
|
|
|
|
encode?: (value: string, token: Key) => string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type Token = string | Key;
|
|
|
|
export type Path = string | RegExp | Array<string | RegExp>;
|
2024-10-16 10:43:44 +00:00
|
|
|
export type PathFunction = (data?: Object, options?: PathFunctionOptions) => string;
|
2024-10-14 06:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export = pathToRegexp;
|