Skip to content

Commit c85fbbb

Browse files
committed
Manually build
1 parent b4e2007 commit c85fbbb

File tree

5 files changed

+543
-3
lines changed

5 files changed

+543
-3
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.vscode/
22
node_modules/
33
coverage/
4-
dist/
54
dist.es2015/

dist/index.d.ts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/**
2+
* Encode a string into another string.
3+
*/
4+
export type Encode = (value: string) => string;
5+
/**
6+
* Decode a string into another string.
7+
*/
8+
export type Decode = (value: string) => string;
9+
export interface ParseOptions {
10+
/**
11+
* A function for encoding input strings.
12+
*/
13+
encodePath?: Encode;
14+
}
15+
export interface PathToRegexpOptions {
16+
/**
17+
* Matches the path completely without trailing characters. (default: `true`)
18+
*/
19+
end?: boolean;
20+
/**
21+
* Allows optional trailing delimiter to match. (default: `true`)
22+
*/
23+
trailing?: boolean;
24+
/**
25+
* Match will be case sensitive. (default: `false`)
26+
*/
27+
sensitive?: boolean;
28+
/**
29+
* The default delimiter for segments. (default: `'/'`)
30+
*/
31+
delimiter?: string;
32+
}
33+
export interface MatchOptions extends PathToRegexpOptions {
34+
/**
35+
* Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`)
36+
*/
37+
decode?: Decode | false;
38+
}
39+
export interface CompileOptions {
40+
/**
41+
* Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)
42+
*/
43+
encode?: Encode | false;
44+
/**
45+
* The default delimiter for segments. (default: `'/'`)
46+
*/
47+
delimiter?: string;
48+
}
49+
/**
50+
* Plain text.
51+
*/
52+
export interface Text {
53+
type: "text";
54+
value: string;
55+
}
56+
/**
57+
* A parameter designed to match arbitrary text within a segment.
58+
*/
59+
export interface Parameter {
60+
type: "param";
61+
name: string;
62+
}
63+
/**
64+
* A wildcard parameter designed to match multiple segments.
65+
*/
66+
export interface Wildcard {
67+
type: "wildcard";
68+
name: string;
69+
}
70+
/**
71+
* A set of possible tokens to expand when matching.
72+
*/
73+
export interface Group {
74+
type: "group";
75+
tokens: Token[];
76+
}
77+
/**
78+
* A token that corresponds with a regexp capture.
79+
*/
80+
export type Key = Parameter | Wildcard;
81+
/**
82+
* A sequence of `path-to-regexp` keys that match capturing groups.
83+
*/
84+
export type Keys = Array<Key>;
85+
/**
86+
* A sequence of path match characters.
87+
*/
88+
export type Token = Text | Parameter | Wildcard | Group;
89+
/**
90+
* Tokenized path instance.
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>(
104+
path: Path,
105+
options?: CompileOptions & ParseOptions,
106+
): (data?: P) => string;
107+
export type ParamData = Partial<Record<string, string | string[]>>;
108+
export type PathFunction<P extends ParamData> = (data?: P) => string;
109+
/**
110+
* A match result contains data about the path match.
111+
*/
112+
export interface MatchResult<P extends ParamData> {
113+
path: string;
114+
params: P;
115+
}
116+
/**
117+
* A match is either `false` (no match) or a match result.
118+
*/
119+
export type Match<P extends ParamData> = false | MatchResult<P>;
120+
/**
121+
* The match function takes a string and returns whether it matched the path.
122+
*/
123+
export type MatchFunction<P extends ParamData> = (path: string) => Match<P>;
124+
/**
125+
* Supported path types.
126+
*/
127+
export type Path = string | TokenData;
128+
/**
129+
* Transform a path into a match function.
130+
*/
131+
export declare function match<P extends ParamData>(
132+
path: Path | Path[],
133+
options?: MatchOptions & ParseOptions,
134+
): MatchFunction<P>;
135+
export declare function pathToRegexp(
136+
path: Path | Path[],
137+
options?: PathToRegexpOptions & ParseOptions,
138+
): {
139+
regexp: RegExp;
140+
keys: Keys;
141+
};
142+
/**
143+
* Stringify token data into a path string.
144+
*/
145+
export declare function stringify(data: TokenData): string;

0 commit comments

Comments
 (0)