1 |
|
2 |
|
3 |
|
4 | export type Encode = (value: string) => string;
|
5 |
|
6 |
|
7 |
|
8 | export type Decode = (value: string) => string;
|
9 | export interface ParseOptions {
|
10 | |
11 |
|
12 |
|
13 | encodePath?: Encode;
|
14 | }
|
15 | export interface PathToRegexpOptions {
|
16 | |
17 |
|
18 |
|
19 | end?: boolean;
|
20 | |
21 |
|
22 |
|
23 | trailing?: boolean;
|
24 | |
25 |
|
26 |
|
27 | sensitive?: boolean;
|
28 | |
29 |
|
30 |
|
31 | delimiter?: string;
|
32 | }
|
33 | export interface MatchOptions extends PathToRegexpOptions {
|
34 | |
35 |
|
36 |
|
37 | decode?: Decode | false;
|
38 | }
|
39 | export interface CompileOptions {
|
40 | |
41 |
|
42 |
|
43 | encode?: Encode | false;
|
44 | |
45 |
|
46 |
|
47 | delimiter?: string;
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 | export interface Text {
|
53 | type: "text";
|
54 | value: string;
|
55 | }
|
56 |
|
57 |
|
58 |
|
59 | export interface Parameter {
|
60 | type: "param";
|
61 | name: string;
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 | export interface Wildcard {
|
67 | type: "wildcard";
|
68 | name: string;
|
69 | }
|
70 |
|
71 |
|
72 |
|
73 | export interface Group {
|
74 | type: "group";
|
75 | tokens: Token[];
|
76 | }
|
77 |
|
78 |
|
79 |
|
80 | export type Key = Parameter | Wildcard;
|
81 |
|
82 |
|
83 |
|
84 | export type Keys = Array<Key>;
|
85 |
|
86 |
|
87 |
|
88 | export type Token = Text | Parameter | Wildcard | Group;
|
89 |
|
90 |
|
91 |
|
92 | export declare class TokenData {
|
93 | readonly tokens: Token[];
|
94 | constructor(tokens: Token[]);
|
95 | }
|
96 | /**
|
97 | * Parse a string for the raw tokens.
|
98 | */
|
99 | export declare function parse(str: string, options?: ParseOptions): TokenData;
|
100 | /**
|
101 | * Compile a string to a template function for the path.
|
102 | */
|
103 | export declare function compile<P extends ParamData = ParamData>(path: Path, options?: CompileOptions & ParseOptions): (data?: P) => string;
|
104 | export type ParamData = Partial<Record<string, string | string[]>>;
|
105 | export type PathFunction<P extends ParamData> = (data?: P) => string;
|
106 | /**
|
107 | * A match result contains data about the path match.
|
108 | */
|
109 | export interface MatchResult<P extends ParamData> {
|
110 | path: string;
|
111 | params: P;
|
112 | }
|
113 |
|
114 |
|
115 |
|
116 | export type Match<P extends ParamData> = false | MatchResult<P>;
|
117 |
|
118 |
|
119 |
|
120 | export type MatchFunction<P extends ParamData> = (path: string) => Match<P>;
|
121 |
|
122 |
|
123 |
|
124 | export type Path = string | TokenData;
|
125 |
|
126 |
|
127 |
|
128 | export declare function match<P extends ParamData>(path: Path | Path[], options?: MatchOptions & ParseOptions): MatchFunction<P>;
|
129 | export declare function pathToRegexp(path: Path | Path[], options?: PathToRegexpOptions & ParseOptions): {
|
130 | regexp: RegExp;
|
131 | keys: Keys;
|
132 | };
|
133 |
|
134 |
|
135 |
|
136 | export declare function stringify(data: TokenData): string;
|