forked from pillarjs/path-to-regexp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
59 lines (49 loc) · 1.75 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
declare function pathToRegexp (path: pathToRegexp.Path, options?: pathToRegexp.Options): pathToRegexp.PathRegExp;
declare function pathToRegexp (path: pathToRegexp.Path, keys: pathToRegexp.Token[], options?: pathToRegexp.Options): pathToRegexp.PathRegExp;
declare namespace pathToRegexp {
export interface PathRegExp extends RegExp {
// An array to be populated with the keys found in the path.
keys: Key[];
}
export interface Options {
// When `true` the route will be case sensitive. (default: `false`)
sensitive?: boolean;
// When `false` the trailing slash is optional. (default: `false`)
strict?: boolean;
// When `false` the path will match at the beginning. (default: `true`)
end?: boolean;
}
/**
* Parse an Express-style path into an array of tokens.
*/
export function parse (path: string): Token[];
/**
* Transforming an Express-style path into a valid path.
*/
export function compile (path: string): PathFunction;
/**
* Transform an array of tokens into a path generator function.
*/
export function tokensToFunction (tokens: Token[]): PathFunction;
/**
* Transform an array of tokens into a matching regular expression.
*/
export function tokensToRegExp (tokens: Token[], options?: Options): PathRegExp;
export interface Key {
name: string | number;
prefix: string;
delimiter: string;
optional: boolean;
repeat: boolean;
pattern: string;
partial: boolean;
asterisk: boolean;
}
interface PathFunctionOptions {
pretty?: boolean;
}
export type Token = string | Key;
export type Path = string | RegExp | Array<string | RegExp>;
export type PathFunction = (data?: Object, options?: PathFunctionOptions) => string;
}
export = pathToRegexp;