forked from pillarjs/path-to-regexp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
83 lines (73 loc) · 2.46 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
declare function pathToRegexp (path: pathToRegexp.Path, keys?: pathToRegexp.Key[], options?: pathToRegexp.RegExpOptions & pathToRegexp.ParseOptions): RegExp;
declare namespace pathToRegexp {
export interface RegExpOptions {
/**
* When `true` the regexp will be case sensitive. (default: `false`)
*/
sensitive?: boolean;
/**
* When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
*/
strict?: boolean;
/**
* When `true` the regexp will match to the end of the string. (default: `true`)
*/
end?: boolean;
/**
* When `true` the regexp will match from the beginning of the string. (default: `true`)
*/
start?: 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[];
/**
* List of characters to consider delimiters when parsing. (default: `undefined`, any character)
*/
whitelist?: string | string[];
}
export interface ParseOptions {
/**
* Set the default delimiter for repeat parameters. (default: `'/'`)
*/
delimiter?: string;
}
/**
* 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.
*/
export function compile <P extends object = object> (path: string, options?: ParseOptions): PathFunction<P>;
/**
* Transform an array of tokens into a path generator function.
*/
export function tokensToFunction <P extends object = object> (tokens: Token[]): PathFunction<P>;
/**
* 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;
}
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>;
export type PathFunction <P extends object = object> = (data?: P, options?: PathFunctionOptions) => string;
}
export = pathToRegexp;