path-to-regexp 6.2.2 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +141 -166
- package/dist/index.d.ts +86 -74
- package/dist/index.js +323 -302
- package/dist/index.js.map +1 -1
- package/package.json +11 -12
- package/dist.es2015/index.js +0 -400
- package/dist.es2015/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
@@ -1,50 +1,97 @@
|
|
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;
|
1
9
|
export interface ParseOptions {
|
2
10
|
/**
|
3
|
-
*
|
11
|
+
* The default delimiter for segments. (default: `'/'`)
|
4
12
|
*/
|
5
13
|
delimiter?: string;
|
6
14
|
/**
|
7
|
-
*
|
15
|
+
* A function for encoding input strings.
|
8
16
|
*/
|
9
|
-
|
17
|
+
encodePath?: Encode;
|
10
18
|
}
|
11
|
-
|
12
|
-
* Parse a string for the raw tokens.
|
13
|
-
*/
|
14
|
-
export declare function parse(str: string, options?: ParseOptions): Token[];
|
15
|
-
export interface TokensToFunctionOptions {
|
19
|
+
export interface PathToRegexpOptions extends ParseOptions {
|
16
20
|
/**
|
17
|
-
*
|
21
|
+
* Regexp will be case sensitive. (default: `false`)
|
18
22
|
*/
|
19
23
|
sensitive?: boolean;
|
20
24
|
/**
|
21
|
-
*
|
25
|
+
* Allow the delimiter to be arbitrarily repeated. (default: `true`)
|
22
26
|
*/
|
23
|
-
|
27
|
+
loose?: boolean;
|
24
28
|
/**
|
25
|
-
*
|
29
|
+
* Verify patterns are valid and safe to use. (default: `false`)
|
30
|
+
*/
|
31
|
+
strict?: boolean;
|
32
|
+
/**
|
33
|
+
* Match from the beginning of the string. (default: `true`)
|
34
|
+
*/
|
35
|
+
start?: boolean;
|
36
|
+
/**
|
37
|
+
* Match to the end of the string. (default: `true`)
|
38
|
+
*/
|
39
|
+
end?: boolean;
|
40
|
+
/**
|
41
|
+
* Allow optional trailing delimiter to match. (default: `true`)
|
42
|
+
*/
|
43
|
+
trailing?: boolean;
|
44
|
+
}
|
45
|
+
export interface MatchOptions extends PathToRegexpOptions {
|
46
|
+
/**
|
47
|
+
* Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`)
|
48
|
+
*/
|
49
|
+
decode?: Decode | false;
|
50
|
+
}
|
51
|
+
export interface CompileOptions extends ParseOptions {
|
52
|
+
/**
|
53
|
+
* Regexp will be case sensitive. (default: `false`)
|
54
|
+
*/
|
55
|
+
sensitive?: boolean;
|
56
|
+
/**
|
57
|
+
* Allow the delimiter to be arbitrarily repeated. (default: `true`)
|
58
|
+
*/
|
59
|
+
loose?: boolean;
|
60
|
+
/**
|
61
|
+
* Verify patterns are valid and safe to use. (default: `false`)
|
62
|
+
*/
|
63
|
+
strict?: boolean;
|
64
|
+
/**
|
65
|
+
* Verifies the function is producing a valid path. (default: `true`)
|
26
66
|
*/
|
27
67
|
validate?: boolean;
|
68
|
+
/**
|
69
|
+
* Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)
|
70
|
+
*/
|
71
|
+
encode?: Encode | false;
|
28
72
|
}
|
29
73
|
/**
|
30
|
-
*
|
74
|
+
* Tokenized path instance. Can we passed around instead of string.
|
31
75
|
*/
|
32
|
-
export declare
|
33
|
-
|
76
|
+
export declare class TokenData {
|
77
|
+
readonly tokens: Token[];
|
78
|
+
readonly delimiter: string;
|
79
|
+
constructor(tokens: Token[], delimiter: string);
|
80
|
+
}
|
34
81
|
/**
|
35
|
-
*
|
82
|
+
* Parse a string for the raw tokens.
|
36
83
|
*/
|
37
|
-
export declare function
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
84
|
+
export declare function parse(str: string, options?: ParseOptions): TokenData;
|
85
|
+
/**
|
86
|
+
* Compile a string to a template function for the path.
|
87
|
+
*/
|
88
|
+
export declare function compile<P extends ParamData = ParamData>(path: Path, options?: CompileOptions): PathFunction<P>;
|
89
|
+
export type ParamData = Partial<Record<string, string | string[]>>;
|
90
|
+
export type PathFunction<P extends ParamData> = (data?: P) => string;
|
44
91
|
/**
|
45
92
|
* A match result contains data about the path match.
|
46
93
|
*/
|
47
|
-
export interface MatchResult<P extends
|
94
|
+
export interface MatchResult<P extends ParamData> {
|
48
95
|
path: string;
|
49
96
|
index: number;
|
50
97
|
params: P;
|
@@ -52,71 +99,34 @@ export interface MatchResult<P extends object = object> {
|
|
52
99
|
/**
|
53
100
|
* A match is either `false` (no match) or a match result.
|
54
101
|
*/
|
55
|
-
export type Match<P extends
|
102
|
+
export type Match<P extends ParamData> = false | MatchResult<P>;
|
56
103
|
/**
|
57
104
|
* The match function takes a string and returns whether it matched the path.
|
58
105
|
*/
|
59
|
-
export type MatchFunction<P extends
|
106
|
+
export type MatchFunction<P extends ParamData> = (path: string) => Match<P>;
|
60
107
|
/**
|
61
108
|
* Create path match function from `path-to-regexp` spec.
|
62
109
|
*/
|
63
|
-
export declare function match<P extends
|
110
|
+
export declare function match<P extends ParamData>(path: Path, options?: MatchOptions): MatchFunction<P>;
|
64
111
|
/**
|
65
|
-
*
|
66
|
-
*/
|
67
|
-
export declare function regexpToFunction<P extends object = object>(re: RegExp, keys: Key[], options?: RegexpToFunctionOptions): MatchFunction<P>;
|
68
|
-
/**
|
69
|
-
* Metadata about a key.
|
112
|
+
* A key is a capture group in the regex.
|
70
113
|
*/
|
71
114
|
export interface Key {
|
72
|
-
name: string
|
73
|
-
prefix
|
74
|
-
suffix
|
75
|
-
pattern
|
76
|
-
modifier
|
115
|
+
name: string;
|
116
|
+
prefix?: string;
|
117
|
+
suffix?: string;
|
118
|
+
pattern?: string;
|
119
|
+
modifier?: string;
|
120
|
+
separator?: string;
|
77
121
|
}
|
78
122
|
/**
|
79
123
|
* A token is a string (nothing special) or key metadata (capture group).
|
80
124
|
*/
|
81
125
|
export type Token = string | Key;
|
82
|
-
export interface TokensToRegexpOptions {
|
83
|
-
/**
|
84
|
-
* When `true` the regexp will be case sensitive. (default: `false`)
|
85
|
-
*/
|
86
|
-
sensitive?: boolean;
|
87
|
-
/**
|
88
|
-
* When `true` the regexp won't allow an optional trailing delimiter to match. (default: `false`)
|
89
|
-
*/
|
90
|
-
strict?: boolean;
|
91
|
-
/**
|
92
|
-
* When `true` the regexp will match to the end of the string. (default: `true`)
|
93
|
-
*/
|
94
|
-
end?: boolean;
|
95
|
-
/**
|
96
|
-
* When `true` the regexp will match from the beginning of the string. (default: `true`)
|
97
|
-
*/
|
98
|
-
start?: boolean;
|
99
|
-
/**
|
100
|
-
* Sets the final character for non-ending optimistic matches. (default: `/`)
|
101
|
-
*/
|
102
|
-
delimiter?: string;
|
103
|
-
/**
|
104
|
-
* List of characters that can also be "end" characters.
|
105
|
-
*/
|
106
|
-
endsWith?: string;
|
107
|
-
/**
|
108
|
-
* Encode path tokens for use in the `RegExp`.
|
109
|
-
*/
|
110
|
-
encode?: (value: string) => string;
|
111
|
-
}
|
112
|
-
/**
|
113
|
-
* Expose a function for taking tokens and returning a RegExp.
|
114
|
-
*/
|
115
|
-
export declare function tokensToRegexp(tokens: Token[], keys?: Key[], options?: TokensToRegexpOptions): RegExp;
|
116
126
|
/**
|
117
|
-
*
|
127
|
+
* Repeated and simple input types.
|
118
128
|
*/
|
119
|
-
export type Path = string |
|
129
|
+
export type Path = string | TokenData;
|
120
130
|
/**
|
121
131
|
* Normalize the given path string, returning a regular expression.
|
122
132
|
*
|
@@ -124,4 +134,6 @@ export type Path = string | RegExp | Array<string | RegExp>;
|
|
124
134
|
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
|
125
135
|
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
|
126
136
|
*/
|
127
|
-
export declare function pathToRegexp(path: Path,
|
137
|
+
export declare function pathToRegexp(path: Path, options?: PathToRegexpOptions): RegExp & {
|
138
|
+
keys: Key[];
|
139
|
+
};
|