path-to-regexp 8.2.0 → 8.4.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 +33 -25
- package/dist/index.d.ts +13 -2
- package/dist/index.js +253 -202
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
package/Readme.md
CHANGED
|
@@ -66,7 +66,7 @@ fn("/users/123/delete");
|
|
|
66
66
|
|
|
67
67
|
The `match` function returns a function for matching strings against a path:
|
|
68
68
|
|
|
69
|
-
- **path** String or array of strings.
|
|
69
|
+
- **path** String, `TokenData` object, or array of strings and `TokenData` objects.
|
|
70
70
|
- **options** _(optional)_ (Extends [pathToRegexp](#pathToRegexp) options)
|
|
71
71
|
- **decode** Function for decoding strings to params, or `false` to disable all processing. (default: `decodeURIComponent`)
|
|
72
72
|
|
|
@@ -78,9 +78,9 @@ const fn = match("/foo/:bar");
|
|
|
78
78
|
|
|
79
79
|
## PathToRegexp
|
|
80
80
|
|
|
81
|
-
The `pathToRegexp` function returns
|
|
81
|
+
The `pathToRegexp` function returns the `regexp` for matching strings against paths, and an array of `keys` for understanding the `RegExp#exec` matches.
|
|
82
82
|
|
|
83
|
-
- **path** String or array of strings.
|
|
83
|
+
- **path** String, `TokenData` object, or array of strings and `TokenData` objects.
|
|
84
84
|
- **options** _(optional)_ (See [parse](#parse) for more options)
|
|
85
85
|
- **sensitive** Regexp will be case sensitive. (default: `false`)
|
|
86
86
|
- **end** Validate the match reaches the end of the string. (default: `true`)
|
|
@@ -89,13 +89,15 @@ The `pathToRegexp` function returns a regular expression for matching strings ag
|
|
|
89
89
|
|
|
90
90
|
```js
|
|
91
91
|
const { regexp, keys } = pathToRegexp("/foo/:bar");
|
|
92
|
+
|
|
93
|
+
regexp.exec("/foo/123"); //=> ["/foo/123", "123"]
|
|
92
94
|
```
|
|
93
95
|
|
|
94
96
|
## Compile ("Reverse" Path-To-RegExp)
|
|
95
97
|
|
|
96
98
|
The `compile` function will return a function for transforming parameters into a valid path:
|
|
97
99
|
|
|
98
|
-
- **path** A string.
|
|
100
|
+
- **path** A string or `TokenData` object.
|
|
99
101
|
- **options** (See [parse](#parse) for more options)
|
|
100
102
|
- **delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` parameters. (default: `'/'`)
|
|
101
103
|
- **encode** Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)
|
|
@@ -119,15 +121,17 @@ toPathRaw({ id: "%3A%2F" }); //=> "/user/%3A%2F"
|
|
|
119
121
|
|
|
120
122
|
## Stringify
|
|
121
123
|
|
|
122
|
-
Transform `TokenData`
|
|
124
|
+
Transform a `TokenData` object to a Path-to-RegExp string.
|
|
123
125
|
|
|
124
|
-
- **data** A `TokenData`
|
|
126
|
+
- **data** A `TokenData` object.
|
|
125
127
|
|
|
126
128
|
```js
|
|
127
|
-
const data =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
const data = {
|
|
130
|
+
tokens: [
|
|
131
|
+
{ type: "text", value: "/" },
|
|
132
|
+
{ type: "param", name: "foo" },
|
|
133
|
+
],
|
|
134
|
+
};
|
|
131
135
|
|
|
132
136
|
const path = stringify(data); //=> "/:foo"
|
|
133
137
|
```
|
|
@@ -139,7 +143,7 @@ const path = stringify(data); //=> "/:foo"
|
|
|
139
143
|
|
|
140
144
|
### Parse
|
|
141
145
|
|
|
142
|
-
The `parse` function accepts a string and returns `TokenData`,
|
|
146
|
+
The `parse` function accepts a string and returns `TokenData`, which can be used with `match` and `compile`.
|
|
143
147
|
|
|
144
148
|
- **path** A string.
|
|
145
149
|
- **options** _(optional)_
|
|
@@ -147,20 +151,24 @@ The `parse` function accepts a string and returns `TokenData`, the set of tokens
|
|
|
147
151
|
|
|
148
152
|
### Tokens
|
|
149
153
|
|
|
150
|
-
`TokenData`
|
|
154
|
+
`TokenData` has two properties:
|
|
155
|
+
|
|
156
|
+
- **tokens** A sequence of tokens, currently of types `text`, `parameter`, `wildcard`, or `group`.
|
|
157
|
+
- **originalPath** The original path used with `parse`, shown in error messages to assist debugging.
|
|
151
158
|
|
|
152
159
|
### Custom path
|
|
153
160
|
|
|
154
|
-
In some applications
|
|
161
|
+
In some applications you may not be able to use the `path-to-regexp` syntax, but you still want to use this library for `match` and `compile`. For example:
|
|
155
162
|
|
|
156
163
|
```js
|
|
157
|
-
import {
|
|
164
|
+
import { match } from "path-to-regexp";
|
|
158
165
|
|
|
159
166
|
const tokens = [
|
|
160
167
|
{ type: "text", value: "/" },
|
|
161
168
|
{ type: "parameter", name: "foo" },
|
|
162
169
|
];
|
|
163
|
-
const
|
|
170
|
+
const originalPath = "/[foo]"; // To help debug error messages.
|
|
171
|
+
const path = { tokens, originalPath };
|
|
164
172
|
const fn = match(path);
|
|
165
173
|
|
|
166
174
|
fn("/test"); //=> { path: '/test', index: 0, params: { foo: 'test' } }
|
|
@@ -170,31 +178,31 @@ fn("/test"); //=> { path: '/test', index: 0, params: { foo: 'test' } }
|
|
|
170
178
|
|
|
171
179
|
An effort has been made to ensure ambiguous paths from previous releases throw an error. This means you might be seeing an error when things worked before.
|
|
172
180
|
|
|
181
|
+
### Missing parameter name
|
|
182
|
+
|
|
183
|
+
Parameter names must be provided after `:` or `*`, for example `/*path`. They can be valid JavaScript identifiers (e.g. `:myName`) or JSON strings (`:"my-name"`).
|
|
184
|
+
|
|
173
185
|
### Unexpected `?` or `+`
|
|
174
186
|
|
|
175
187
|
In past releases, `?`, `*`, and `+` were used to denote optional or repeating parameters. As an alternative, try these:
|
|
176
188
|
|
|
177
|
-
- For optional (`?`), use
|
|
178
|
-
- For
|
|
179
|
-
- For
|
|
189
|
+
- For optional (`?`), use braces: `/file{.:ext}`.
|
|
190
|
+
- For one or more (`+`), use a wildcard: `/*path`.
|
|
191
|
+
- For zero or more (`*`), use both: `/files{/*path}`.
|
|
180
192
|
|
|
181
193
|
### Unexpected `(`, `)`, `[`, `]`, etc.
|
|
182
194
|
|
|
183
|
-
Previous versions of Path-to-RegExp used these for RegExp features. This version no longer supports them so they've been reserved to avoid ambiguity. To
|
|
184
|
-
|
|
185
|
-
### Missing parameter name
|
|
186
|
-
|
|
187
|
-
Parameter names must be provided after `:` or `*`, and they must be a valid JavaScript identifier. If you want an parameter name that isn't a JavaScript identifier, such as starting with a number, you can wrap the name in quotes like `:"my-name"`.
|
|
195
|
+
Previous versions of Path-to-RegExp used these for RegExp features. This version no longer supports them so they've been reserved to avoid ambiguity. To match these characters literally, escape them with a backslash, e.g. `"\\("`.
|
|
188
196
|
|
|
189
197
|
### Unterminated quote
|
|
190
198
|
|
|
191
|
-
Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character.
|
|
199
|
+
Parameter names can be wrapped in double quote characters, and this error means you forgot to close the quote character. For example, `:"foo`.
|
|
192
200
|
|
|
193
201
|
### Express <= 4.x
|
|
194
202
|
|
|
195
203
|
Path-To-RegExp breaks compatibility with Express <= `4.x` in the following ways:
|
|
196
204
|
|
|
197
|
-
- The wildcard `*` must have a name
|
|
205
|
+
- The wildcard `*` must have a name and matches the behavior of parameters `:`.
|
|
198
206
|
- The optional character `?` is no longer supported, use braces instead: `/:file{.:ext}`.
|
|
199
207
|
- Regexp characters are not supported.
|
|
200
208
|
- Some characters have been reserved to avoid confusion during upgrade (`()[]?+!`).
|
package/dist/index.d.ts
CHANGED
|
@@ -91,7 +91,15 @@ export type Token = Text | Parameter | Wildcard | Group;
|
|
|
91
91
|
*/
|
|
92
92
|
export declare class TokenData {
|
|
93
93
|
readonly tokens: Token[];
|
|
94
|
-
|
|
94
|
+
readonly originalPath?: string | undefined;
|
|
95
|
+
constructor(tokens: Token[], originalPath?: string | undefined);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* ParseError is thrown when there is an error processing the path.
|
|
99
|
+
*/
|
|
100
|
+
export declare class PathError extends TypeError {
|
|
101
|
+
readonly originalPath: string | undefined;
|
|
102
|
+
constructor(message: string, originalPath: string | undefined);
|
|
95
103
|
}
|
|
96
104
|
/**
|
|
97
105
|
* Parse a string for the raw tokens.
|
|
@@ -100,7 +108,7 @@ export declare function parse(str: string, options?: ParseOptions): TokenData;
|
|
|
100
108
|
/**
|
|
101
109
|
* Compile a string to a template function for the path.
|
|
102
110
|
*/
|
|
103
|
-
export declare function compile<P extends ParamData = ParamData>(path: Path, options?: CompileOptions & ParseOptions): (
|
|
111
|
+
export declare function compile<P extends ParamData = ParamData>(path: Path, options?: CompileOptions & ParseOptions): (params?: P) => string;
|
|
104
112
|
export type ParamData = Partial<Record<string, string | string[]>>;
|
|
105
113
|
export type PathFunction<P extends ParamData> = (data?: P) => string;
|
|
106
114
|
/**
|
|
@@ -126,6 +134,9 @@ export type Path = string | TokenData;
|
|
|
126
134
|
* Transform a path into a match function.
|
|
127
135
|
*/
|
|
128
136
|
export declare function match<P extends ParamData>(path: Path | Path[], options?: MatchOptions & ParseOptions): MatchFunction<P>;
|
|
137
|
+
/**
|
|
138
|
+
* Transform a path into a regular expression and capture keys.
|
|
139
|
+
*/
|
|
129
140
|
export declare function pathToRegexp(path: Path | Path[], options?: PathToRegexpOptions & ParseOptions): {
|
|
130
141
|
regexp: RegExp;
|
|
131
142
|
keys: Keys;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenData = void 0;
|
|
3
|
+
exports.PathError = exports.TokenData = void 0;
|
|
4
4
|
exports.parse = parse;
|
|
5
5
|
exports.compile = compile;
|
|
6
6
|
exports.match = match;
|
|
@@ -10,25 +10,13 @@ const DEFAULT_DELIMITER = "/";
|
|
|
10
10
|
const NOOP_VALUE = (value) => value;
|
|
11
11
|
const ID_START = /^[$_\p{ID_Start}]$/u;
|
|
12
12
|
const ID_CONTINUE = /^[$\u200c\u200d\p{ID_Continue}]$/u;
|
|
13
|
-
const
|
|
14
|
-
const SIMPLE_TOKENS = {
|
|
15
|
-
// Groups.
|
|
16
|
-
"{": "{",
|
|
17
|
-
"}": "}",
|
|
18
|
-
// Reserved.
|
|
19
|
-
"(": "(",
|
|
20
|
-
")": ")",
|
|
21
|
-
"[": "[",
|
|
22
|
-
"]": "]",
|
|
23
|
-
"+": "+",
|
|
24
|
-
"?": "?",
|
|
25
|
-
"!": "!",
|
|
26
|
-
};
|
|
13
|
+
const ID = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
|
|
14
|
+
const SIMPLE_TOKENS = "{}()[]+?!";
|
|
27
15
|
/**
|
|
28
16
|
* Escape text for stringify to path.
|
|
29
17
|
*/
|
|
30
18
|
function escapeText(str) {
|
|
31
|
-
return str.replace(/[{}()\[\]
|
|
19
|
+
return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
|
|
32
20
|
}
|
|
33
21
|
/**
|
|
34
22
|
* Escape a regular expression string.
|
|
@@ -37,161 +25,134 @@ function escape(str) {
|
|
|
37
25
|
return str.replace(/[.+*?^${}()[\]|/\\]/g, "\\$&");
|
|
38
26
|
}
|
|
39
27
|
/**
|
|
40
|
-
*
|
|
28
|
+
* Tokenized path instance.
|
|
29
|
+
*/
|
|
30
|
+
class TokenData {
|
|
31
|
+
constructor(tokens, originalPath) {
|
|
32
|
+
this.tokens = tokens;
|
|
33
|
+
this.originalPath = originalPath;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.TokenData = TokenData;
|
|
37
|
+
/**
|
|
38
|
+
* ParseError is thrown when there is an error processing the path.
|
|
39
|
+
*/
|
|
40
|
+
class PathError extends TypeError {
|
|
41
|
+
constructor(message, originalPath) {
|
|
42
|
+
let text = message;
|
|
43
|
+
if (originalPath)
|
|
44
|
+
text += `: ${originalPath}`;
|
|
45
|
+
text += `; visit https://git.new/pathToRegexpError for info`;
|
|
46
|
+
super(text);
|
|
47
|
+
this.originalPath = originalPath;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.PathError = PathError;
|
|
51
|
+
/**
|
|
52
|
+
* Parse a string for the raw tokens.
|
|
41
53
|
*/
|
|
42
|
-
function
|
|
54
|
+
function parse(str, options = {}) {
|
|
55
|
+
const { encodePath = NOOP_VALUE } = options;
|
|
43
56
|
const chars = [...str];
|
|
44
|
-
|
|
57
|
+
const tokens = [];
|
|
58
|
+
let index = 0;
|
|
59
|
+
let pos = 0;
|
|
45
60
|
function name() {
|
|
46
61
|
let value = "";
|
|
47
|
-
if (ID_START.test(chars[
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
62
|
+
if (ID_START.test(chars[index])) {
|
|
63
|
+
do {
|
|
64
|
+
value += chars[index++];
|
|
65
|
+
} while (ID_CONTINUE.test(chars[index]));
|
|
52
66
|
}
|
|
53
|
-
else if (chars[
|
|
54
|
-
let
|
|
55
|
-
while (
|
|
56
|
-
if (chars[++
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
else if (chars[index] === '"') {
|
|
68
|
+
let quoteStart = index;
|
|
69
|
+
while (index < chars.length) {
|
|
70
|
+
if (chars[++index] === '"') {
|
|
71
|
+
index++;
|
|
72
|
+
quoteStart = 0;
|
|
59
73
|
break;
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
value += chars[i];
|
|
66
|
-
}
|
|
75
|
+
// Increment over escape characters.
|
|
76
|
+
if (chars[index] === "\\")
|
|
77
|
+
index++;
|
|
78
|
+
value += chars[index];
|
|
67
79
|
}
|
|
68
|
-
if (
|
|
69
|
-
throw new
|
|
80
|
+
if (quoteStart) {
|
|
81
|
+
throw new PathError(`Unterminated quote at index ${quoteStart}`, str);
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
if (!value) {
|
|
73
|
-
throw new
|
|
85
|
+
throw new PathError(`Missing parameter name at index ${index}`, str);
|
|
74
86
|
}
|
|
75
87
|
return value;
|
|
76
88
|
}
|
|
77
|
-
while (
|
|
78
|
-
const value = chars[
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
yield { type, index: i++, value };
|
|
89
|
+
while (index < chars.length) {
|
|
90
|
+
const value = chars[index++];
|
|
91
|
+
if (SIMPLE_TOKENS.includes(value)) {
|
|
92
|
+
tokens.push({ type: value, index, value });
|
|
82
93
|
}
|
|
83
94
|
else if (value === "\\") {
|
|
84
|
-
|
|
95
|
+
tokens.push({ type: "escape", index, value: chars[index++] });
|
|
85
96
|
}
|
|
86
97
|
else if (value === ":") {
|
|
87
|
-
|
|
88
|
-
yield { type: "PARAM", index: i, value };
|
|
98
|
+
tokens.push({ type: "param", index, value: name() });
|
|
89
99
|
}
|
|
90
100
|
else if (value === "*") {
|
|
91
|
-
|
|
92
|
-
yield { type: "WILDCARD", index: i, value };
|
|
101
|
+
tokens.push({ type: "wildcard", index, value: name() });
|
|
93
102
|
}
|
|
94
103
|
else {
|
|
95
|
-
|
|
104
|
+
tokens.push({ type: "char", index, value });
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
constructor(tokens) {
|
|
102
|
-
this.tokens = tokens;
|
|
103
|
-
}
|
|
104
|
-
peek() {
|
|
105
|
-
if (!this._peek) {
|
|
106
|
-
const next = this.tokens.next();
|
|
107
|
-
this._peek = next.value;
|
|
108
|
-
}
|
|
109
|
-
return this._peek;
|
|
110
|
-
}
|
|
111
|
-
tryConsume(type) {
|
|
112
|
-
const token = this.peek();
|
|
113
|
-
if (token.type !== type)
|
|
114
|
-
return;
|
|
115
|
-
this._peek = undefined; // Reset after consumed.
|
|
116
|
-
return token.value;
|
|
117
|
-
}
|
|
118
|
-
consume(type) {
|
|
119
|
-
const value = this.tryConsume(type);
|
|
120
|
-
if (value !== undefined)
|
|
121
|
-
return value;
|
|
122
|
-
const { type: nextType, index } = this.peek();
|
|
123
|
-
throw new TypeError(`Unexpected ${nextType} at ${index}, expected ${type}: ${DEBUG_URL}`);
|
|
124
|
-
}
|
|
125
|
-
text() {
|
|
126
|
-
let result = "";
|
|
127
|
-
let value;
|
|
128
|
-
while ((value = this.tryConsume("CHAR") || this.tryConsume("ESCAPED"))) {
|
|
129
|
-
result += value;
|
|
130
|
-
}
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Tokenized path instance.
|
|
136
|
-
*/
|
|
137
|
-
class TokenData {
|
|
138
|
-
constructor(tokens) {
|
|
139
|
-
this.tokens = tokens;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.TokenData = TokenData;
|
|
143
|
-
/**
|
|
144
|
-
* Parse a string for the raw tokens.
|
|
145
|
-
*/
|
|
146
|
-
function parse(str, options = {}) {
|
|
147
|
-
const { encodePath = NOOP_VALUE } = options;
|
|
148
|
-
const it = new Iter(lexer(str));
|
|
149
|
-
function consume(endType) {
|
|
150
|
-
const tokens = [];
|
|
107
|
+
tokens.push({ type: "end", index, value: "" });
|
|
108
|
+
function consumeUntil(endType) {
|
|
109
|
+
const output = [];
|
|
151
110
|
while (true) {
|
|
152
|
-
const
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
tokens
|
|
158
|
-
|
|
159
|
-
|
|
111
|
+
const token = tokens[pos++];
|
|
112
|
+
if (token.type === endType)
|
|
113
|
+
break;
|
|
114
|
+
if (token.type === "char" || token.type === "escape") {
|
|
115
|
+
let path = token.value;
|
|
116
|
+
let cur = tokens[pos];
|
|
117
|
+
while (cur.type === "char" || cur.type === "escape") {
|
|
118
|
+
path += cur.value;
|
|
119
|
+
cur = tokens[++pos];
|
|
120
|
+
}
|
|
121
|
+
output.push({
|
|
122
|
+
type: "text",
|
|
123
|
+
value: encodePath(path),
|
|
160
124
|
});
|
|
161
125
|
continue;
|
|
162
126
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
name: wildcard,
|
|
127
|
+
if (token.type === "param" || token.type === "wildcard") {
|
|
128
|
+
output.push({
|
|
129
|
+
type: token.type,
|
|
130
|
+
name: token.value,
|
|
168
131
|
});
|
|
169
132
|
continue;
|
|
170
133
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
tokens.push({
|
|
134
|
+
if (token.type === "{") {
|
|
135
|
+
output.push({
|
|
174
136
|
type: "group",
|
|
175
|
-
tokens:
|
|
137
|
+
tokens: consumeUntil("}"),
|
|
176
138
|
});
|
|
177
139
|
continue;
|
|
178
140
|
}
|
|
179
|
-
|
|
180
|
-
return tokens;
|
|
141
|
+
throw new PathError(`Unexpected ${token.type} at index ${token.index}, expected ${endType}`, str);
|
|
181
142
|
}
|
|
143
|
+
return output;
|
|
182
144
|
}
|
|
183
|
-
|
|
184
|
-
return new TokenData(tokens);
|
|
145
|
+
return new TokenData(consumeUntil("end"), str);
|
|
185
146
|
}
|
|
186
147
|
/**
|
|
187
148
|
* Compile a string to a template function for the path.
|
|
188
149
|
*/
|
|
189
150
|
function compile(path, options = {}) {
|
|
190
151
|
const { encode = encodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
|
|
191
|
-
const data = path
|
|
152
|
+
const data = typeof path === "object" ? path : parse(path, options);
|
|
192
153
|
const fn = tokensToFunction(data.tokens, delimiter, encode);
|
|
193
|
-
return function path(
|
|
194
|
-
const [path, ...missing] = fn(
|
|
154
|
+
return function path(params = {}) {
|
|
155
|
+
const [path, ...missing] = fn(params);
|
|
195
156
|
if (missing.length) {
|
|
196
157
|
throw new TypeError(`Missing parameters: ${missing.join(", ")}`);
|
|
197
158
|
}
|
|
@@ -285,119 +246,209 @@ function match(path, options = {}) {
|
|
|
285
246
|
return { path, params };
|
|
286
247
|
};
|
|
287
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Transform a path into a regular expression and capture keys.
|
|
251
|
+
*/
|
|
288
252
|
function pathToRegexp(path, options = {}) {
|
|
289
253
|
const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true, } = options;
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
sources.push(regexp);
|
|
254
|
+
const root = new SourceNode("^");
|
|
255
|
+
const paths = [path];
|
|
256
|
+
let combinations = 0;
|
|
257
|
+
while (paths.length) {
|
|
258
|
+
const path = paths.shift();
|
|
259
|
+
if (Array.isArray(path)) {
|
|
260
|
+
paths.push(...path);
|
|
261
|
+
continue;
|
|
299
262
|
}
|
|
263
|
+
const data = typeof path === "object" ? path : parse(path, options);
|
|
264
|
+
flatten(data.tokens, 0, [], (tokens) => {
|
|
265
|
+
if (combinations++ >= 256) {
|
|
266
|
+
throw new PathError("Too many path combinations", data.originalPath);
|
|
267
|
+
}
|
|
268
|
+
let node = root;
|
|
269
|
+
for (const part of toRegExpSource(tokens, delimiter, data.originalPath)) {
|
|
270
|
+
node = node.add(part.source, part.key);
|
|
271
|
+
}
|
|
272
|
+
node.add(""); // Mark the end of the source.
|
|
273
|
+
});
|
|
300
274
|
}
|
|
301
|
-
|
|
275
|
+
const keys = [];
|
|
276
|
+
let pattern = toRegExp(root, keys);
|
|
302
277
|
if (trailing)
|
|
303
|
-
pattern +=
|
|
304
|
-
pattern += end ? "$" :
|
|
305
|
-
|
|
306
|
-
|
|
278
|
+
pattern += "(?:" + escape(delimiter) + "$)?";
|
|
279
|
+
pattern += end ? "$" : "(?=" + escape(delimiter) + "|$)";
|
|
280
|
+
return { regexp: new RegExp(pattern, sensitive ? "" : "i"), keys };
|
|
281
|
+
}
|
|
282
|
+
function toRegExp(node, keys) {
|
|
283
|
+
if (node.key)
|
|
284
|
+
keys.push(node.key);
|
|
285
|
+
const children = Object.keys(node.children);
|
|
286
|
+
const text = children
|
|
287
|
+
.map((id) => toRegExp(node.children[id], keys))
|
|
288
|
+
.join("|");
|
|
289
|
+
return node.source + (children.length < 2 ? text : `(?:${text})`);
|
|
290
|
+
}
|
|
291
|
+
class SourceNode {
|
|
292
|
+
constructor(source, key) {
|
|
293
|
+
this.source = source;
|
|
294
|
+
this.key = key;
|
|
295
|
+
this.children = Object.create(null);
|
|
296
|
+
}
|
|
297
|
+
add(source, key) {
|
|
298
|
+
var _a;
|
|
299
|
+
const id = source + ":" + (key ? key.name : "");
|
|
300
|
+
return ((_a = this.children)[id] || (_a[id] = new SourceNode(source, key)));
|
|
301
|
+
}
|
|
307
302
|
}
|
|
308
303
|
/**
|
|
309
304
|
* Generate a flat list of sequence tokens from the given tokens.
|
|
310
305
|
*/
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const fork = init.slice();
|
|
318
|
-
for (const seq of flatten(token.tokens, 0, fork)) {
|
|
319
|
-
yield* flatten(tokens, index + 1, seq);
|
|
306
|
+
function flatten(tokens, index, result, callback) {
|
|
307
|
+
while (index < tokens.length) {
|
|
308
|
+
const token = tokens[index++];
|
|
309
|
+
if (token.type === "group") {
|
|
310
|
+
flatten(token.tokens, 0, result.slice(), (seq) => flatten(tokens, index, seq, callback));
|
|
311
|
+
continue;
|
|
320
312
|
}
|
|
313
|
+
result.push(token);
|
|
321
314
|
}
|
|
322
|
-
|
|
323
|
-
init.push(token);
|
|
324
|
-
}
|
|
325
|
-
yield* flatten(tokens, index + 1, init);
|
|
315
|
+
callback(result);
|
|
326
316
|
}
|
|
327
317
|
/**
|
|
328
318
|
* Transform a flat sequence of tokens into a regular expression.
|
|
329
319
|
*/
|
|
330
|
-
function
|
|
331
|
-
let result =
|
|
320
|
+
function toRegExpSource(tokens, delimiter, originalPath) {
|
|
321
|
+
let result = [];
|
|
332
322
|
let backtrack = "";
|
|
333
|
-
let
|
|
334
|
-
|
|
335
|
-
|
|
323
|
+
let wildcardBacktrack = "";
|
|
324
|
+
let prevCaptureType = 0;
|
|
325
|
+
let hasSegmentCapture = 0;
|
|
326
|
+
let index = 0;
|
|
327
|
+
function hasInSegment(index, type) {
|
|
328
|
+
while (index < tokens.length) {
|
|
329
|
+
const token = tokens[index++];
|
|
330
|
+
if (token.type === type)
|
|
331
|
+
return true;
|
|
332
|
+
if (token.type === "text") {
|
|
333
|
+
if (token.value.includes(delimiter))
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
function peekText(index) {
|
|
340
|
+
let result = "";
|
|
341
|
+
while (index < tokens.length) {
|
|
342
|
+
const token = tokens[index++];
|
|
343
|
+
if (token.type !== "text")
|
|
344
|
+
break;
|
|
345
|
+
result += token.value;
|
|
346
|
+
}
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
while (index < tokens.length) {
|
|
350
|
+
const token = tokens[index++];
|
|
336
351
|
if (token.type === "text") {
|
|
337
|
-
result
|
|
352
|
+
result.push({ source: escape(token.value) });
|
|
338
353
|
backtrack += token.value;
|
|
339
|
-
|
|
354
|
+
if (prevCaptureType === 2)
|
|
355
|
+
wildcardBacktrack += token.value;
|
|
356
|
+
if (token.value.includes(delimiter))
|
|
357
|
+
hasSegmentCapture = 0;
|
|
340
358
|
continue;
|
|
341
359
|
}
|
|
342
360
|
if (token.type === "param" || token.type === "wildcard") {
|
|
343
|
-
if (
|
|
344
|
-
throw new
|
|
361
|
+
if (prevCaptureType && !backtrack) {
|
|
362
|
+
throw new PathError(`Missing text before "${token.name}" ${token.type}`, originalPath);
|
|
345
363
|
}
|
|
346
364
|
if (token.type === "param") {
|
|
347
|
-
result
|
|
365
|
+
result.push({
|
|
366
|
+
source: hasSegmentCapture // Seen param/wildcard in segment.
|
|
367
|
+
? `(${negate(delimiter, backtrack)}+?)`
|
|
368
|
+
: hasInSegment(index, "wildcard") // See wildcard later in segment.
|
|
369
|
+
? `(${negate(delimiter, peekText(index))}+?)`
|
|
370
|
+
: `(${negate(delimiter, "")}+?)`,
|
|
371
|
+
key: token,
|
|
372
|
+
});
|
|
373
|
+
hasSegmentCapture |= prevCaptureType = 1;
|
|
348
374
|
}
|
|
349
375
|
else {
|
|
350
|
-
result
|
|
376
|
+
result.push({
|
|
377
|
+
source: hasSegmentCapture & 2 // Seen wildcard in segment.
|
|
378
|
+
? `(${negate(backtrack, "")}+?)`
|
|
379
|
+
: hasSegmentCapture & 1 // Seen param in segment.
|
|
380
|
+
? `(${negate(wildcardBacktrack, "")}+?)`
|
|
381
|
+
: wildcardBacktrack // No capture in segment, seen wildcard in path.
|
|
382
|
+
? `(${negate(wildcardBacktrack, "")}+?|${negate(delimiter, "")}+?)`
|
|
383
|
+
: `([^]+?)`,
|
|
384
|
+
key: token,
|
|
385
|
+
});
|
|
386
|
+
wildcardBacktrack = "";
|
|
387
|
+
hasSegmentCapture |= prevCaptureType = 2;
|
|
351
388
|
}
|
|
352
|
-
keys.push(token);
|
|
353
389
|
backtrack = "";
|
|
354
|
-
isSafeSegmentParam = false;
|
|
355
390
|
continue;
|
|
356
391
|
}
|
|
392
|
+
throw new TypeError(`Unknown token type: ${token.type}`);
|
|
357
393
|
}
|
|
358
394
|
return result;
|
|
359
395
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Block backtracking on previous text/delimiter.
|
|
398
|
+
*/
|
|
399
|
+
function negate(a, b) {
|
|
400
|
+
if (b.length > a.length)
|
|
401
|
+
return negate(b, a); // Longest string first.
|
|
402
|
+
if (a === b)
|
|
403
|
+
b = ""; // Cleaner regex strings, no duplication.
|
|
404
|
+
if (b.length > 1)
|
|
405
|
+
return `(?:(?!${escape(a)}|${escape(b)})[^])`;
|
|
406
|
+
if (a.length > 1)
|
|
407
|
+
return `(?:(?!${escape(a)})[^${escape(b)}])`;
|
|
408
|
+
return `[^${escape(a + b)}]`;
|
|
370
409
|
}
|
|
371
410
|
/**
|
|
372
|
-
* Stringify
|
|
411
|
+
* Stringify an array of tokens into a path string.
|
|
373
412
|
*/
|
|
374
|
-
function
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
413
|
+
function stringifyTokens(tokens, index) {
|
|
414
|
+
let value = "";
|
|
415
|
+
while (index < tokens.length) {
|
|
416
|
+
const token = tokens[index++];
|
|
417
|
+
if (token.type === "text") {
|
|
418
|
+
value += escapeText(token.value);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
379
421
|
if (token.type === "group") {
|
|
380
|
-
|
|
422
|
+
value += "{" + stringifyTokens(token.tokens, 0) + "}";
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (token.type === "param") {
|
|
426
|
+
value += ":" + stringifyName(token.name, tokens[index]);
|
|
427
|
+
continue;
|
|
381
428
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
})
|
|
390
|
-
.join("");
|
|
429
|
+
if (token.type === "wildcard") {
|
|
430
|
+
value += "*" + stringifyName(token.name, tokens[index]);
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
throw new TypeError(`Unknown token type: ${token.type}`);
|
|
434
|
+
}
|
|
435
|
+
return value;
|
|
391
436
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return
|
|
437
|
+
/**
|
|
438
|
+
* Stringify token data into a path string.
|
|
439
|
+
*/
|
|
440
|
+
function stringify(data) {
|
|
441
|
+
return stringifyTokens(data.tokens, 0);
|
|
397
442
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
443
|
+
/**
|
|
444
|
+
* Stringify a parameter name, escaping when it cannot be emitted directly.
|
|
445
|
+
*/
|
|
446
|
+
function stringifyName(name, next) {
|
|
447
|
+
if (!ID.test(name))
|
|
448
|
+
return JSON.stringify(name);
|
|
449
|
+
if ((next === null || next === void 0 ? void 0 : next.type) === "text" && ID_CONTINUE.test(next.value[0])) {
|
|
450
|
+
return JSON.stringify(name);
|
|
451
|
+
}
|
|
452
|
+
return name;
|
|
402
453
|
}
|
|
403
454
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAoRA,sBA6CC;AAKD,0BAgBC;AAgHD,sBA+BC;AAED,oCA+BC;AAsFD,8BAiBC;AA7mBD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC;AAC5C,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,MAAM,WAAW,GAAG,mCAAmC,CAAC;AACxD,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAkFtD,MAAM,aAAa,GAA8B;IAC/C,UAAU;IACV,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,YAAY;IACZ,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;CACT,CAAC;AAEF;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG,CAAC,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAW;IACzB,MAAM,KAAK,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;IACvB,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,SAAS,IAAI;QACX,IAAI,KAAK,GAAG,EAAE,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DELIMITER = \"/\";\nconst NOOP_VALUE = (value: string) => value;\nconst ID_START = /^[$_\\p{ID_Start}]$/u;\nconst ID_CONTINUE = /^[$\\u200c\\u200d\\p{ID_Continue}]$/u;\nconst DEBUG_URL = \"https://git.new/pathToRegexpError\";\n\n/**\n * Encode a string into another string.\n */\nexport type Encode = (value: string) => string;\n\n/**\n * Decode a string into another string.\n */\nexport type Decode = (value: string) => string;\n\nexport interface ParseOptions {\n /**\n * A function for encoding input strings.\n */\n encodePath?: Encode;\n}\n\nexport interface PathToRegexpOptions {\n /**\n * Matches the path completely without trailing characters. (default: `true`)\n */\n end?: boolean;\n /**\n * Allows optional trailing delimiter to match. (default: `true`)\n */\n trailing?: boolean;\n /**\n * Match will be case sensitive. (default: `false`)\n */\n sensitive?: boolean;\n /**\n * The default delimiter for segments. (default: `'/'`)\n */\n delimiter?: string;\n}\n\nexport interface MatchOptions extends PathToRegexpOptions {\n /**\n * Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`)\n */\n decode?: Decode | false;\n}\n\nexport interface CompileOptions {\n /**\n * Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)\n */\n encode?: Encode | false;\n /**\n * The default delimiter for segments. (default: `'/'`)\n */\n delimiter?: string;\n}\n\ntype TokenType =\n | \"{\"\n | \"}\"\n | \"WILDCARD\"\n | \"PARAM\"\n | \"CHAR\"\n | \"ESCAPED\"\n | \"END\"\n // Reserved for use or ambiguous due to past use.\n | \"(\"\n | \")\"\n | \"[\"\n | \"]\"\n | \"+\"\n | \"?\"\n | \"!\";\n\n/**\n * Tokenizer results.\n */\ninterface LexToken {\n type: TokenType;\n index: number;\n value: string;\n}\n\nconst SIMPLE_TOKENS: Record<string, TokenType> = {\n // Groups.\n \"{\": \"{\",\n \"}\": \"}\",\n // Reserved.\n \"(\": \"(\",\n \")\": \")\",\n \"[\": \"[\",\n \"]\": \"]\",\n \"+\": \"+\",\n \"?\": \"?\",\n \"!\": \"!\",\n};\n\n/**\n * Escape text for stringify to path.\n */\nfunction escapeText(str: string) {\n return str.replace(/[{}()\\[\\]+?!:*]/g, \"\\\\$&\");\n}\n\n/**\n * Escape a regular expression string.\n */\nfunction escape(str: string) {\n return str.replace(/[.+*?^${}()[\\]|/\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Tokenize input string.\n */\nfunction* lexer(str: string): Generator<LexToken, LexToken> {\n const chars = [...str];\n let i = 0;\n\n function name() {\n let value = \"\";\n\n if (ID_START.test(chars[++i])) {\n value += chars[i];\n while (ID_CONTINUE.test(chars[++i])) {\n value += chars[i];\n }\n } else if (chars[i] === '\"') {\n let pos = i;\n\n while (i < chars.length) {\n if (chars[++i] === '\"') {\n i++;\n pos = 0;\n break;\n }\n\n if (chars[i] === \"\\\\\") {\n value += chars[++i];\n } else {\n value += chars[i];\n }\n }\n\n if (pos) {\n throw new TypeError(`Unterminated quote at ${pos}: ${DEBUG_URL}`);\n }\n }\n\n if (!value) {\n throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`);\n }\n\n return value;\n }\n\n while (i < chars.length) {\n const value = chars[i];\n const type = SIMPLE_TOKENS[value];\n\n if (type) {\n yield { type, index: i++, value };\n } else if (value === \"\\\\\") {\n yield { type: \"ESCAPED\", index: i++, value: chars[i++] };\n } else if (value === \":\") {\n const value = name();\n yield { type: \"PARAM\", index: i, value };\n } else if (value === \"*\") {\n const value = name();\n yield { type: \"WILDCARD\", index: i, value };\n } else {\n yield { type: \"CHAR\", index: i, value: chars[i++] };\n }\n }\n\n return { type: \"END\", index: i, value: \"\" };\n}\n\nclass Iter {\n private _peek?: LexToken;\n\n constructor(private tokens: Generator<LexToken, LexToken>) {}\n\n peek(): LexToken {\n if (!this._peek) {\n const next = this.tokens.next();\n this._peek = next.value;\n }\n return this._peek;\n }\n\n tryConsume(type: TokenType): string | undefined {\n const token = this.peek();\n if (token.type !== type) return;\n this._peek = undefined; // Reset after consumed.\n return token.value;\n }\n\n consume(type: TokenType): string {\n const value = this.tryConsume(type);\n if (value !== undefined) return value;\n const { type: nextType, index } = this.peek();\n throw new TypeError(\n `Unexpected ${nextType} at ${index}, expected ${type}: ${DEBUG_URL}`,\n );\n }\n\n text(): string {\n let result = \"\";\n let value: string | undefined;\n while ((value = this.tryConsume(\"CHAR\") || this.tryConsume(\"ESCAPED\"))) {\n result += value;\n }\n return result;\n }\n}\n\n/**\n * Plain text.\n */\nexport interface Text {\n type: \"text\";\n value: string;\n}\n\n/**\n * A parameter designed to match arbitrary text within a segment.\n */\nexport interface Parameter {\n type: \"param\";\n name: string;\n}\n\n/**\n * A wildcard parameter designed to match multiple segments.\n */\nexport interface Wildcard {\n type: \"wildcard\";\n name: string;\n}\n\n/**\n * A set of possible tokens to expand when matching.\n */\nexport interface Group {\n type: \"group\";\n tokens: Token[];\n}\n\n/**\n * A token that corresponds with a regexp capture.\n */\nexport type Key = Parameter | Wildcard;\n\n/**\n * A sequence of `path-to-regexp` keys that match capturing groups.\n */\nexport type Keys = Array<Key>;\n\n/**\n * A sequence of path match characters.\n */\nexport type Token = Text | Parameter | Wildcard | Group;\n\n/**\n * Tokenized path instance.\n */\nexport class TokenData {\n constructor(public readonly tokens: Token[]) {}\n}\n\n/**\n * Parse a string for the raw tokens.\n */\nexport function parse(str: string, options: ParseOptions = {}): TokenData {\n const { encodePath = NOOP_VALUE } = options;\n const it = new Iter(lexer(str));\n\n function consume(endType: TokenType): Token[] {\n const tokens: Token[] = [];\n\n while (true) {\n const path = it.text();\n if (path) tokens.push({ type: \"text\", value: encodePath(path) });\n\n const param = it.tryConsume(\"PARAM\");\n if (param) {\n tokens.push({\n type: \"param\",\n name: param,\n });\n continue;\n }\n\n const wildcard = it.tryConsume(\"WILDCARD\");\n if (wildcard) {\n tokens.push({\n type: \"wildcard\",\n name: wildcard,\n });\n continue;\n }\n\n const open = it.tryConsume(\"{\");\n if (open) {\n tokens.push({\n type: \"group\",\n tokens: consume(\"}\"),\n });\n continue;\n }\n\n it.consume(endType);\n return tokens;\n }\n }\n\n const tokens = consume(\"END\");\n return new TokenData(tokens);\n}\n\n/**\n * Compile a string to a template function for the path.\n */\nexport function compile<P extends ParamData = ParamData>(\n path: Path,\n options: CompileOptions & ParseOptions = {},\n) {\n const { encode = encodeURIComponent, delimiter = DEFAULT_DELIMITER } =\n options;\n const data = path instanceof TokenData ? path : parse(path, options);\n const fn = tokensToFunction(data.tokens, delimiter, encode);\n\n return function path(data: P = {} as P) {\n const [path, ...missing] = fn(data);\n if (missing.length) {\n throw new TypeError(`Missing parameters: ${missing.join(\", \")}`);\n }\n return path;\n };\n}\n\nexport type ParamData = Partial<Record<string, string | string[]>>;\nexport type PathFunction<P extends ParamData> = (data?: P) => string;\n\nfunction tokensToFunction(\n tokens: Token[],\n delimiter: string,\n encode: Encode | false,\n) {\n const encoders = tokens.map((token) =>\n tokenToFunction(token, delimiter, encode),\n );\n\n return (data: ParamData) => {\n const result: string[] = [\"\"];\n\n for (const encoder of encoders) {\n const [value, ...extras] = encoder(data);\n result[0] += value;\n result.push(...extras);\n }\n\n return result;\n };\n}\n\n/**\n * Convert a single token into a path building function.\n */\nfunction tokenToFunction(\n token: Token,\n delimiter: string,\n encode: Encode | false,\n): (data: ParamData) => string[] {\n if (token.type === \"text\") return () => [token.value];\n\n if (token.type === \"group\") {\n const fn = tokensToFunction(token.tokens, delimiter, encode);\n\n return (data) => {\n const [value, ...missing] = fn(data);\n if (!missing.length) return [value];\n return [\"\"];\n };\n }\n\n const encodeValue = encode || NOOP_VALUE;\n\n if (token.type === \"wildcard\" && encode !== false) {\n return (data) => {\n const value = data[token.name];\n if (value == null) return [\"\", token.name];\n\n if (!Array.isArray(value) || value.length === 0) {\n throw new TypeError(`Expected \"${token.name}\" to be a non-empty array`);\n }\n\n return [\n value\n .map((value, index) => {\n if (typeof value !== \"string\") {\n throw new TypeError(\n `Expected \"${token.name}/${index}\" to be a string`,\n );\n }\n\n return encodeValue(value);\n })\n .join(delimiter),\n ];\n };\n }\n\n return (data) => {\n const value = data[token.name];\n if (value == null) return [\"\", token.name];\n\n if (typeof value !== \"string\") {\n throw new TypeError(`Expected \"${token.name}\" to be a string`);\n }\n\n return [encodeValue(value)];\n };\n}\n\n/**\n * A match result contains data about the path match.\n */\nexport interface MatchResult<P extends ParamData> {\n path: string;\n params: P;\n}\n\n/**\n * A match is either `false` (no match) or a match result.\n */\nexport type Match<P extends ParamData> = false | MatchResult<P>;\n\n/**\n * The match function takes a string and returns whether it matched the path.\n */\nexport type MatchFunction<P extends ParamData> = (path: string) => Match<P>;\n\n/**\n * Supported path types.\n */\nexport type Path = string | TokenData;\n\n/**\n * Transform a path into a match function.\n */\nexport function match<P extends ParamData>(\n path: Path | Path[],\n options: MatchOptions & ParseOptions = {},\n): MatchFunction<P> {\n const { decode = decodeURIComponent, delimiter = DEFAULT_DELIMITER } =\n options;\n const { regexp, keys } = pathToRegexp(path, options);\n\n const decoders = keys.map((key) => {\n if (decode === false) return NOOP_VALUE;\n if (key.type === \"param\") return decode;\n return (value: string) => value.split(delimiter).map(decode);\n });\n\n return function match(input: string) {\n const m = regexp.exec(input);\n if (!m) return false;\n\n const path = m[0];\n const params = Object.create(null);\n\n for (let i = 1; i < m.length; i++) {\n if (m[i] === undefined) continue;\n\n const key = keys[i - 1];\n const decoder = decoders[i - 1];\n params[key.name] = decoder(m[i]);\n }\n\n return { path, params };\n };\n}\n\nexport function pathToRegexp(\n path: Path | Path[],\n options: PathToRegexpOptions & ParseOptions = {},\n) {\n const {\n delimiter = DEFAULT_DELIMITER,\n end = true,\n sensitive = false,\n trailing = true,\n } = options;\n const keys: Keys = [];\n const sources: string[] = [];\n const flags = sensitive ? \"\" : \"i\";\n const paths = Array.isArray(path) ? path : [path];\n const items = paths.map((path) =>\n path instanceof TokenData ? path : parse(path, options),\n );\n\n for (const { tokens } of items) {\n for (const seq of flatten(tokens, 0, [])) {\n const regexp = sequenceToRegExp(seq, delimiter, keys);\n sources.push(regexp);\n }\n }\n\n let pattern = `^(?:${sources.join(\"|\")})`;\n if (trailing) pattern += `(?:${escape(delimiter)}$)?`;\n pattern += end ? \"$\" : `(?=${escape(delimiter)}|$)`;\n\n const regexp = new RegExp(pattern, flags);\n return { regexp, keys };\n}\n\n/**\n * Flattened token set.\n */\ntype Flattened = Text | Parameter | Wildcard;\n\n/**\n * Generate a flat list of sequence tokens from the given tokens.\n */\nfunction* flatten(\n tokens: Token[],\n index: number,\n init: Flattened[],\n): Generator<Flattened[]> {\n if (index === tokens.length) {\n return yield init;\n }\n\n const token = tokens[index];\n\n if (token.type === \"group\") {\n const fork = init.slice();\n for (const seq of flatten(token.tokens, 0, fork)) {\n yield* flatten(tokens, index + 1, seq);\n }\n } else {\n init.push(token);\n }\n\n yield* flatten(tokens, index + 1, init);\n}\n\n/**\n * Transform a flat sequence of tokens into a regular expression.\n */\nfunction sequenceToRegExp(tokens: Flattened[], delimiter: string, keys: Keys) {\n let result = \"\";\n let backtrack = \"\";\n let isSafeSegmentParam = true;\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n\n if (token.type === \"text\") {\n result += escape(token.value);\n backtrack += token.value;\n isSafeSegmentParam ||= token.value.includes(delimiter);\n continue;\n }\n\n if (token.type === \"param\" || token.type === \"wildcard\") {\n if (!isSafeSegmentParam && !backtrack) {\n throw new TypeError(`Missing text after \"${token.name}\": ${DEBUG_URL}`);\n }\n\n if (token.type === \"param\") {\n result += `(${negate(delimiter, isSafeSegmentParam ? \"\" : backtrack)}+)`;\n } else {\n result += `([\\\\s\\\\S]+)`;\n }\n\n keys.push(token);\n backtrack = \"\";\n isSafeSegmentParam = false;\n continue;\n }\n }\n\n return result;\n}\n\nfunction negate(delimiter: string, backtrack: string) {\n if (backtrack.length < 2) {\n if (delimiter.length < 2) return `[^${escape(delimiter + backtrack)}]`;\n return `(?:(?!${escape(delimiter)})[^${escape(backtrack)}])`;\n }\n if (delimiter.length < 2) {\n return `(?:(?!${escape(backtrack)})[^${escape(delimiter)}])`;\n }\n return `(?:(?!${escape(backtrack)}|${escape(delimiter)})[\\\\s\\\\S])`;\n}\n\n/**\n * Stringify token data into a path string.\n */\nexport function stringify(data: TokenData) {\n return data.tokens\n .map(function stringifyToken(token, index, tokens): string {\n if (token.type === \"text\") return escapeText(token.value);\n if (token.type === \"group\") {\n return `{${token.tokens.map(stringifyToken).join(\"\")}}`;\n }\n\n const isSafe =\n isNameSafe(token.name) && isNextNameSafe(tokens[index + 1]);\n const key = isSafe ? token.name : JSON.stringify(token.name);\n\n if (token.type === \"param\") return `:${key}`;\n if (token.type === \"wildcard\") return `*${key}`;\n throw new TypeError(`Unexpected token: ${token}`);\n })\n .join(\"\");\n}\n\nfunction isNameSafe(name: string) {\n const [first, ...rest] = name;\n if (!ID_START.test(first)) return false;\n return rest.every((char) => ID_CONTINUE.test(char));\n}\n\nfunction isNextNameSafe(token: Token | undefined) {\n if (token?.type !== \"text\") return true;\n return !ID_CONTINUE.test(token.value[0]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAiLA,sBA6GC;AAKD,0BAgBC;AAgHD,sBA+BC;AAKD,oCA4CC;AA2MD,8BAEC;AAhsBD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC;AAC5C,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,MAAM,WAAW,GAAG,mCAAmC,CAAC;AACxD,MAAM,EAAE,GAAG,oDAAoD,CAAC;AAkFhE,MAAM,aAAa,GAAG,WAAW,CAAC;AAElC;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;AACrD,CAA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AC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["const DEFAULT_DELIMITER = \"/\";\nconst NOOP_VALUE = (value: string) => value;\nconst ID_START = /^[$_\\p{ID_Start}]$/u;\nconst ID_CONTINUE = /^[$\\u200c\\u200d\\p{ID_Continue}]$/u;\nconst ID = /^[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*$/u;\n\n/**\n * Encode a string into another string.\n */\nexport type Encode = (value: string) => string;\n\n/**\n * Decode a string into another string.\n */\nexport type Decode = (value: string) => string;\n\nexport interface ParseOptions {\n /**\n * A function for encoding input strings.\n */\n encodePath?: Encode;\n}\n\nexport interface PathToRegexpOptions {\n /**\n * Matches the path completely without trailing characters. (default: `true`)\n */\n end?: boolean;\n /**\n * Allows optional trailing delimiter to match. (default: `true`)\n */\n trailing?: boolean;\n /**\n * Match will be case sensitive. (default: `false`)\n */\n sensitive?: boolean;\n /**\n * The default delimiter for segments. (default: `'/'`)\n */\n delimiter?: string;\n}\n\nexport interface MatchOptions extends PathToRegexpOptions {\n /**\n * Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`)\n */\n decode?: Decode | false;\n}\n\nexport interface CompileOptions {\n /**\n * Function for encoding input strings for output into the path, or `false` to disable entirely. (default: `encodeURIComponent`)\n */\n encode?: Encode | false;\n /**\n * The default delimiter for segments. (default: `'/'`)\n */\n delimiter?: string;\n}\n\ntype TokenType =\n | \"{\"\n | \"}\"\n | \"wildcard\"\n | \"param\"\n | \"char\"\n | \"escape\"\n | \"end\"\n // Reserved for use or ambiguous due to past use.\n | \"(\"\n | \")\"\n | \"[\"\n | \"]\"\n | \"+\"\n | \"?\"\n | \"!\";\n\n/**\n * Tokenizer results.\n */\ninterface LexToken {\n type: TokenType;\n index: number;\n value: string;\n}\n\nconst SIMPLE_TOKENS = \"{}()[]+?!\";\n\n/**\n * Escape text for stringify to path.\n */\nfunction escapeText(str: string) {\n return str.replace(/[{}()\\[\\]+?!:*\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Escape a regular expression string.\n */\nfunction escape(str: string) {\n return str.replace(/[.+*?^${}()[\\]|/\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Plain text.\n */\nexport interface Text {\n type: \"text\";\n value: string;\n}\n\n/**\n * A parameter designed to match arbitrary text within a segment.\n */\nexport interface Parameter {\n type: \"param\";\n name: string;\n}\n\n/**\n * A wildcard parameter designed to match multiple segments.\n */\nexport interface Wildcard {\n type: \"wildcard\";\n name: string;\n}\n\n/**\n * A set of possible tokens to expand when matching.\n */\nexport interface Group {\n type: \"group\";\n tokens: Token[];\n}\n\n/**\n * A token that corresponds with a regexp capture.\n */\nexport type Key = Parameter | Wildcard;\n\n/**\n * A sequence of `path-to-regexp` keys that match capturing groups.\n */\nexport type Keys = Array<Key>;\n\n/**\n * A sequence of path match characters.\n */\nexport type Token = Text | Parameter | Wildcard | Group;\n\n/**\n * Tokenized path instance.\n */\nexport class TokenData {\n constructor(\n public readonly tokens: Token[],\n public readonly originalPath?: string,\n ) {}\n}\n\n/**\n * ParseError is thrown when there is an error processing the path.\n */\nexport class PathError extends TypeError {\n constructor(\n message: string,\n public readonly originalPath: string | undefined,\n ) {\n let text = message;\n if (originalPath) text += `: ${originalPath}`;\n text += `; visit https://git.new/pathToRegexpError for info`;\n super(text);\n }\n}\n\n/**\n * Parse a string for the raw tokens.\n */\nexport function parse(str: string, options: ParseOptions = {}): TokenData {\n const { encodePath = NOOP_VALUE } = options;\n const chars = [...str];\n const tokens: Array<LexToken> = [];\n let index = 0;\n let pos = 0;\n\n function name() {\n let value = \"\";\n\n if (ID_START.test(chars[index])) {\n do {\n value += chars[index++];\n } while (ID_CONTINUE.test(chars[index]));\n } else if (chars[index] === '\"') {\n let quoteStart = index;\n\n while (index < chars.length) {\n if (chars[++index] === '\"') {\n index++;\n quoteStart = 0;\n break;\n }\n\n // Increment over escape characters.\n if (chars[index] === \"\\\\\") index++;\n\n value += chars[index];\n }\n\n if (quoteStart) {\n throw new PathError(`Unterminated quote at index ${quoteStart}`, str);\n }\n }\n\n if (!value) {\n throw new PathError(`Missing parameter name at index ${index}`, str);\n }\n\n return value;\n }\n\n while (index < chars.length) {\n const value = chars[index++];\n\n if (SIMPLE_TOKENS.includes(value)) {\n tokens.push({ type: value as TokenType, index, value });\n } else if (value === \"\\\\\") {\n tokens.push({ type: \"escape\", index, value: chars[index++] });\n } else if (value === \":\") {\n tokens.push({ type: \"param\", index, value: name() });\n } else if (value === \"*\") {\n tokens.push({ type: \"wildcard\", index, value: name() });\n } else {\n tokens.push({ type: \"char\", index, value });\n }\n }\n\n tokens.push({ type: \"end\", index, value: \"\" });\n\n function consumeUntil(endType: TokenType): Token[] {\n const output: Token[] = [];\n\n while (true) {\n const token = tokens[pos++];\n if (token.type === endType) break;\n\n if (token.type === \"char\" || token.type === \"escape\") {\n let path = token.value;\n let cur = tokens[pos];\n\n while (cur.type === \"char\" || cur.type === \"escape\") {\n path += cur.value;\n cur = tokens[++pos];\n }\n\n output.push({\n type: \"text\",\n value: encodePath(path),\n });\n continue;\n }\n\n if (token.type === \"param\" || token.type === \"wildcard\") {\n output.push({\n type: token.type,\n name: token.value,\n });\n continue;\n }\n\n if (token.type === \"{\") {\n output.push({\n type: \"group\",\n tokens: consumeUntil(\"}\"),\n });\n continue;\n }\n\n throw new PathError(\n `Unexpected ${token.type} at index ${token.index}, expected ${endType}`,\n str,\n );\n }\n\n return output;\n }\n\n return new TokenData(consumeUntil(\"end\"), str);\n}\n\n/**\n * Compile a string to a template function for the path.\n */\nexport function compile<P extends ParamData = ParamData>(\n path: Path,\n options: CompileOptions & ParseOptions = {},\n) {\n const { encode = encodeURIComponent, delimiter = DEFAULT_DELIMITER } =\n options;\n const data = typeof path === \"object\" ? path : parse(path, options);\n const fn = tokensToFunction(data.tokens, delimiter, encode);\n\n return function path(params: P = {} as P) {\n const [path, ...missing] = fn(params);\n if (missing.length) {\n throw new TypeError(`Missing parameters: ${missing.join(\", \")}`);\n }\n return path;\n };\n}\n\nexport type ParamData = Partial<Record<string, string | string[]>>;\nexport type PathFunction<P extends ParamData> = (data?: P) => string;\n\nfunction tokensToFunction(\n tokens: Token[],\n delimiter: string,\n encode: Encode | false,\n) {\n const encoders = tokens.map((token) =>\n tokenToFunction(token, delimiter, encode),\n );\n\n return (data: ParamData) => {\n const result: string[] = [\"\"];\n\n for (const encoder of encoders) {\n const [value, ...extras] = encoder(data);\n result[0] += value;\n result.push(...extras);\n }\n\n return result;\n };\n}\n\n/**\n * Convert a single token into a path building function.\n */\nfunction tokenToFunction(\n token: Token,\n delimiter: string,\n encode: Encode | false,\n): (data: ParamData) => string[] {\n if (token.type === \"text\") return () => [token.value];\n\n if (token.type === \"group\") {\n const fn = tokensToFunction(token.tokens, delimiter, encode);\n\n return (data) => {\n const [value, ...missing] = fn(data);\n if (!missing.length) return [value];\n return [\"\"];\n };\n }\n\n const encodeValue = encode || NOOP_VALUE;\n\n if (token.type === \"wildcard\" && encode !== false) {\n return (data) => {\n const value = data[token.name];\n if (value == null) return [\"\", token.name];\n\n if (!Array.isArray(value) || value.length === 0) {\n throw new TypeError(`Expected \"${token.name}\" to be a non-empty array`);\n }\n\n return [\n value\n .map((value, index) => {\n if (typeof value !== \"string\") {\n throw new TypeError(\n `Expected \"${token.name}/${index}\" to be a string`,\n );\n }\n\n return encodeValue(value);\n })\n .join(delimiter),\n ];\n };\n }\n\n return (data) => {\n const value = data[token.name];\n if (value == null) return [\"\", token.name];\n\n if (typeof value !== \"string\") {\n throw new TypeError(`Expected \"${token.name}\" to be a string`);\n }\n\n return [encodeValue(value)];\n };\n}\n\n/**\n * A match result contains data about the path match.\n */\nexport interface MatchResult<P extends ParamData> {\n path: string;\n params: P;\n}\n\n/**\n * A match is either `false` (no match) or a match result.\n */\nexport type Match<P extends ParamData> = false | MatchResult<P>;\n\n/**\n * The match function takes a string and returns whether it matched the path.\n */\nexport type MatchFunction<P extends ParamData> = (path: string) => Match<P>;\n\n/**\n * Supported path types.\n */\nexport type Path = string | TokenData;\n\n/**\n * Transform a path into a match function.\n */\nexport function match<P extends ParamData>(\n path: Path | Path[],\n options: MatchOptions & ParseOptions = {},\n): MatchFunction<P> {\n const { decode = decodeURIComponent, delimiter = DEFAULT_DELIMITER } =\n options;\n const { regexp, keys } = pathToRegexp(path, options);\n\n const decoders = keys.map((key) => {\n if (decode === false) return NOOP_VALUE;\n if (key.type === \"param\") return decode;\n return (value: string) => value.split(delimiter).map(decode);\n });\n\n return function match(input: string) {\n const m = regexp.exec(input);\n if (!m) return false;\n\n const path = m[0];\n const params = Object.create(null);\n\n for (let i = 1; i < m.length; i++) {\n if (m[i] === undefined) continue;\n\n const key = keys[i - 1];\n const decoder = decoders[i - 1];\n params[key.name] = decoder(m[i]);\n }\n\n return { path, params };\n };\n}\n\n/**\n * Transform a path into a regular expression and capture keys.\n */\nexport function pathToRegexp(\n path: Path | Path[],\n options: PathToRegexpOptions & ParseOptions = {},\n) {\n const {\n delimiter = DEFAULT_DELIMITER,\n end = true,\n sensitive = false,\n trailing = true,\n } = options;\n const root = new SourceNode(\"^\");\n const paths: Array<Path | Path[]> = [path];\n let combinations = 0;\n\n while (paths.length) {\n const path = paths.shift()!;\n\n if (Array.isArray(path)) {\n paths.push(...path);\n continue;\n }\n\n const data = typeof path === \"object\" ? path : parse(path, options);\n flatten(data.tokens, 0, [], (tokens) => {\n if (combinations++ >= 256) {\n throw new PathError(\"Too many path combinations\", data.originalPath);\n }\n\n let node = root;\n\n for (const part of toRegExpSource(tokens, delimiter, data.originalPath)) {\n node = node.add(part.source, part.key);\n }\n\n node.add(\"\"); // Mark the end of the source.\n });\n }\n\n const keys: Keys = [];\n let pattern = toRegExp(root, keys);\n if (trailing) pattern += \"(?:\" + escape(delimiter) + \"$)?\";\n pattern += end ? \"$\" : \"(?=\" + escape(delimiter) + \"|$)\";\n\n return { regexp: new RegExp(pattern, sensitive ? \"\" : \"i\"), keys };\n}\n\nfunction toRegExp(node: SourceNode, keys: Keys): string {\n if (node.key) keys.push(node.key);\n\n const children = Object.keys(node.children);\n const text = children\n .map((id) => toRegExp(node.children[id], keys))\n .join(\"|\");\n\n return node.source + (children.length < 2 ? text : `(?:${text})`);\n}\n\nclass SourceNode {\n children: Record<string, SourceNode> = Object.create(null);\n\n constructor(\n public source: string,\n public key?: Key,\n ) {}\n\n add(source: string, key?: Key) {\n const id = source + \":\" + (key ? key.name : \"\");\n return (this.children[id] ||= new SourceNode(source, key));\n }\n}\n\n/**\n * Generate a flat list of sequence tokens from the given tokens.\n */\nfunction flatten(\n tokens: Token[],\n index: number,\n result: Exclude<Token, Group>[],\n callback: (result: Exclude<Token, Group>[]) => void,\n): void {\n while (index < tokens.length) {\n const token = tokens[index++];\n\n if (token.type === \"group\") {\n flatten(token.tokens, 0, result.slice(), (seq) =>\n flatten(tokens, index, seq, callback),\n );\n continue;\n }\n\n result.push(token);\n }\n\n callback(result);\n}\n\n/**\n * Simplest token for the trie deduplication.\n */\ninterface RegExpPart {\n source: string;\n key?: Key;\n}\n\n/**\n * Transform a flat sequence of tokens into a regular expression.\n */\nfunction toRegExpSource(\n tokens: Exclude<Token, Group>[],\n delimiter: string,\n originalPath: string | undefined,\n): RegExpPart[] {\n let result: RegExpPart[] = [];\n let backtrack = \"\";\n let wildcardBacktrack = \"\";\n let prevCaptureType: 0 | 1 | 2 = 0;\n let hasSegmentCapture = 0;\n let index = 0;\n\n function hasInSegment(index: number, type: TokenType) {\n while (index < tokens.length) {\n const token = tokens[index++];\n if (token.type === type) return true;\n if (token.type === \"text\") {\n if (token.value.includes(delimiter)) break;\n }\n }\n return false;\n }\n\n function peekText(index: number) {\n let result = \"\";\n while (index < tokens.length) {\n const token = tokens[index++];\n if (token.type !== \"text\") break;\n result += token.value;\n }\n return result;\n }\n\n while (index < tokens.length) {\n const token = tokens[index++];\n\n if (token.type === \"text\") {\n result.push({ source: escape(token.value) });\n backtrack += token.value;\n if (prevCaptureType === 2) wildcardBacktrack += token.value;\n if (token.value.includes(delimiter)) hasSegmentCapture = 0;\n continue;\n }\n\n if (token.type === \"param\" || token.type === \"wildcard\") {\n if (prevCaptureType && !backtrack) {\n throw new PathError(\n `Missing text before \"${token.name}\" ${token.type}`,\n originalPath,\n );\n }\n\n if (token.type === \"param\") {\n result.push({\n source: hasSegmentCapture // Seen param/wildcard in segment.\n ? `(${negate(delimiter, backtrack)}+?)`\n : hasInSegment(index, \"wildcard\") // See wildcard later in segment.\n ? `(${negate(delimiter, peekText(index))}+?)`\n : `(${negate(delimiter, \"\")}+?)`,\n key: token,\n });\n\n hasSegmentCapture |= prevCaptureType = 1;\n } else {\n result.push({\n source:\n hasSegmentCapture & 2 // Seen wildcard in segment.\n ? `(${negate(backtrack, \"\")}+?)`\n : hasSegmentCapture & 1 // Seen param in segment.\n ? `(${negate(wildcardBacktrack, \"\")}+?)`\n : wildcardBacktrack // No capture in segment, seen wildcard in path.\n ? `(${negate(wildcardBacktrack, \"\")}+?|${negate(delimiter, \"\")}+?)`\n : `([^]+?)`,\n key: token,\n });\n\n wildcardBacktrack = \"\";\n hasSegmentCapture |= prevCaptureType = 2;\n }\n\n backtrack = \"\";\n continue;\n }\n\n throw new TypeError(`Unknown token type: ${(token as any).type}`);\n }\n\n return result;\n}\n\n/**\n * Block backtracking on previous text/delimiter.\n */\nfunction negate(a: string, b: string): string {\n if (b.length > a.length) return negate(b, a); // Longest string first.\n\n if (a === b) b = \"\"; // Cleaner regex strings, no duplication.\n if (b.length > 1) return `(?:(?!${escape(a)}|${escape(b)})[^])`;\n if (a.length > 1) return `(?:(?!${escape(a)})[^${escape(b)}])`;\n return `[^${escape(a + b)}]`;\n}\n\n/**\n * Stringify an array of tokens into a path string.\n */\nfunction stringifyTokens(tokens: Token[], index: number): string {\n let value = \"\";\n\n while (index < tokens.length) {\n const token = tokens[index++];\n\n if (token.type === \"text\") {\n value += escapeText(token.value);\n continue;\n }\n\n if (token.type === \"group\") {\n value += \"{\" + stringifyTokens(token.tokens, 0) + \"}\";\n continue;\n }\n\n if (token.type === \"param\") {\n value += \":\" + stringifyName(token.name, tokens[index]);\n continue;\n }\n\n if (token.type === \"wildcard\") {\n value += \"*\" + stringifyName(token.name, tokens[index]);\n continue;\n }\n\n throw new TypeError(`Unknown token type: ${(token as any).type}`);\n }\n\n return value;\n}\n\n/**\n * Stringify token data into a path string.\n */\nexport function stringify(data: TokenData): string {\n return stringifyTokens(data.tokens, 0);\n}\n\n/**\n * Stringify a parameter name, escaping when it cannot be emitted directly.\n */\nfunction stringifyName(name: string, next: Token | undefined): string {\n if (!ID.test(name)) return JSON.stringify(name);\n\n if (next?.type === \"text\" && ID_CONTINUE.test(next.value[0])) {\n return JSON.stringify(name);\n }\n\n return name;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "path-to-regexp",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "Express style path to RegExp utility",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"express",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/pillarjs/path-to-regexp.git"
|
|
14
14
|
},
|
|
15
|
+
"funding": {
|
|
16
|
+
"type": "opencollective",
|
|
17
|
+
"url": "https://opencollective.com/express"
|
|
18
|
+
},
|
|
15
19
|
"license": "MIT",
|
|
16
20
|
"exports": "./dist/index.js",
|
|
17
21
|
"main": "dist/index.js",
|
|
@@ -34,13 +38,11 @@
|
|
|
34
38
|
"@size-limit/preset-small-lib": "^11.1.2",
|
|
35
39
|
"@types/node": "^22.7.2",
|
|
36
40
|
"@types/semver": "^7.3.1",
|
|
37
|
-
"@vitest/coverage-v8": "^
|
|
38
|
-
"recheck": "^4.
|
|
41
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
42
|
+
"recheck": "^4.5.0",
|
|
39
43
|
"size-limit": "^11.1.2",
|
|
40
|
-
"typescript": "^5.
|
|
41
|
-
|
|
42
|
-
"engines": {
|
|
43
|
-
"node": ">=16"
|
|
44
|
+
"typescript": "^5.7.3",
|
|
45
|
+
"vitest": "^3.0.5"
|
|
44
46
|
},
|
|
45
47
|
"publishConfig": {
|
|
46
48
|
"access": "public"
|
|
@@ -48,7 +50,7 @@
|
|
|
48
50
|
"size-limit": [
|
|
49
51
|
{
|
|
50
52
|
"path": "dist/index.js",
|
|
51
|
-
"limit": "2.
|
|
53
|
+
"limit": "2.15 kB"
|
|
52
54
|
}
|
|
53
55
|
],
|
|
54
56
|
"ts-scripts": {
|