@jsenv/server 15.0.1 → 15.0.3

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.
Files changed (53) hide show
  1. package/README.md +23 -23
  2. package/package.json +4 -4
  3. package/src/content_negotiation/pick_accepted_content.js +13 -13
  4. package/src/content_negotiation/pick_content_encoding.js +25 -25
  5. package/src/content_negotiation/pick_content_language.js +35 -34
  6. package/src/content_negotiation/pick_content_type.js +29 -29
  7. package/src/fetch_filesystem.js +110 -107
  8. package/src/from_fetch_response.js +6 -6
  9. package/src/interfacing_with_node/body.js +22 -22
  10. package/src/interfacing_with_node/observable.js +80 -80
  11. package/src/interfacing_with_node/observable_from_node_stream.js +35 -35
  12. package/src/interfacing_with_node/request_factory.js +26 -26
  13. package/src/interfacing_with_node/write_node_response.js +82 -82
  14. package/src/internal/colorizeResponseStatus.js +26 -26
  15. package/src/internal/convertFileSystemErrorToResponseProperties.js +10 -10
  16. package/src/internal/dns_resolution.js +7 -7
  17. package/src/internal/etag.js +11 -11
  18. package/src/internal/filesystem.js +19 -19
  19. package/src/internal/headersFromObject.js +8 -8
  20. package/src/internal/headersFromString.js +11 -11
  21. package/src/internal/headersToObject.js +5 -5
  22. package/src/internal/headersToString.js +7 -7
  23. package/src/internal/headers_composition.js +9 -9
  24. package/src/internal/hostname_parser.js +9 -9
  25. package/src/internal/listen.js +47 -47
  26. package/src/internal/listenClientError.js +10 -10
  27. package/src/internal/listenEvent.js +5 -5
  28. package/src/internal/listenRequest.js +8 -8
  29. package/src/internal/listenServerConnectionError.js +19 -19
  30. package/src/internal/multiple-header.js +50 -50
  31. package/src/internal/normalizeHeaderName.js +4 -4
  32. package/src/internal/normalizeHeaderValue.js +2 -2
  33. package/src/internal/object_composition.js +41 -39
  34. package/src/internal/response_composition.js +6 -6
  35. package/src/internal/server-polyglot.js +42 -42
  36. package/src/internal/server_ips.js +20 -20
  37. package/src/internal/trackServerPendingConnections.js +23 -23
  38. package/src/internal/trackServerPendingRequests.js +28 -28
  39. package/src/main.js +18 -18
  40. package/src/readRequestBody.js +15 -15
  41. package/src/serve_directory.js +16 -16
  42. package/src/server_timing/timing_header.js +24 -24
  43. package/src/server_timing/timing_measure.js +14 -14
  44. package/src/service_composition/path_to_regexp.js +173 -168
  45. package/src/service_composition/routing.js +12 -12
  46. package/src/service_controller.js +77 -77
  47. package/src/services/cors/jsenv_service_cors.js +29 -29
  48. package/src/services/error_handler/jsenv_service_error_handler.js +18 -18
  49. package/src/services/request_aliases/jsenv_service_request_aliases.js +20 -20
  50. package/src/services/response_acceptance_check/jsenv_service_response_acceptance_check.js +16 -16
  51. package/src/sse/sse_room.js +117 -115
  52. package/src/start_server.js +328 -328
  53. package/src/stopReasons.js +9 -9
@@ -5,31 +5,31 @@
5
5
  * Tokenize input string.
6
6
  */
7
7
  function lexer(str) {
8
- var tokens = []
9
- var i = 0
8
+ var tokens = [];
9
+ var i = 0;
10
10
  while (i < str.length) {
11
- var char = str[i]
11
+ var char = str[i];
12
12
  if (char === "*" || char === "+" || char === "?") {
13
- tokens.push({ type: "MODIFIER", index: i, value: str[i++] })
14
- continue
13
+ tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
14
+ continue;
15
15
  }
16
16
  if (char === "\\") {
17
- tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] })
18
- continue
17
+ tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
18
+ continue;
19
19
  }
20
20
  if (char === "{") {
21
- tokens.push({ type: "OPEN", index: i, value: str[i++] })
22
- continue
21
+ tokens.push({ type: "OPEN", index: i, value: str[i++] });
22
+ continue;
23
23
  }
24
24
  if (char === "}") {
25
- tokens.push({ type: "CLOSE", index: i, value: str[i++] })
26
- continue
25
+ tokens.push({ type: "CLOSE", index: i, value: str[i++] });
26
+ continue;
27
27
  }
28
28
  if (char === ":") {
29
- var name = ""
30
- let j = i + 1
29
+ var name = "";
30
+ let j = i + 1;
31
31
  while (j < str.length) {
32
- var code = str.charCodeAt(j)
32
+ var code = str.charCodeAt(j);
33
33
  if (
34
34
  // `0-9`
35
35
  (code >= 48 && code <= 57) ||
@@ -40,104 +40,104 @@ function lexer(str) {
40
40
  // `_`
41
41
  code === 95
42
42
  ) {
43
- name += str[j++]
44
- continue
43
+ name += str[j++];
44
+ continue;
45
45
  }
46
- break
46
+ break;
47
47
  }
48
- if (!name) throw new TypeError("Missing parameter name at ".concat(i))
49
- tokens.push({ type: "NAME", index: i, value: name })
50
- i = j
51
- continue
48
+ if (!name) throw new TypeError("Missing parameter name at ".concat(i));
49
+ tokens.push({ type: "NAME", index: i, value: name });
50
+ i = j;
51
+ continue;
52
52
  }
53
53
  if (char === "(") {
54
- var count = 1
55
- var pattern = ""
56
- var j = i + 1
54
+ var count = 1;
55
+ var pattern = "";
56
+ var j = i + 1;
57
57
  if (str[j] === "?") {
58
- throw new TypeError('Pattern cannot start with "?" at '.concat(j))
58
+ throw new TypeError('Pattern cannot start with "?" at '.concat(j));
59
59
  }
60
60
  while (j < str.length) {
61
61
  if (str[j] === "\\") {
62
- pattern += str[j++] + str[j++]
63
- continue
62
+ pattern += str[j++] + str[j++];
63
+ continue;
64
64
  }
65
65
  if (str[j] === ")") {
66
- count--
66
+ count--;
67
67
  if (count === 0) {
68
- j++
69
- break
68
+ j++;
69
+ break;
70
70
  }
71
71
  } else if (str[j] === "(") {
72
- count++
72
+ count++;
73
73
  if (str[j + 1] !== "?") {
74
74
  throw new TypeError(
75
75
  "Capturing groups are not allowed at ".concat(j),
76
- )
76
+ );
77
77
  }
78
78
  }
79
- pattern += str[j++]
79
+ pattern += str[j++];
80
80
  }
81
- if (count) throw new TypeError("Unbalanced pattern at ".concat(i))
82
- if (!pattern) throw new TypeError("Missing pattern at ".concat(i))
83
- tokens.push({ type: "PATTERN", index: i, value: pattern })
84
- i = j
85
- continue
81
+ if (count) throw new TypeError("Unbalanced pattern at ".concat(i));
82
+ if (!pattern) throw new TypeError("Missing pattern at ".concat(i));
83
+ tokens.push({ type: "PATTERN", index: i, value: pattern });
84
+ i = j;
85
+ continue;
86
86
  }
87
- tokens.push({ type: "CHAR", index: i, value: str[i++] })
87
+ tokens.push({ type: "CHAR", index: i, value: str[i++] });
88
88
  }
89
- tokens.push({ type: "END", index: i, value: "" })
90
- return tokens
89
+ tokens.push({ type: "END", index: i, value: "" });
90
+ return tokens;
91
91
  }
92
92
  /**
93
93
  * Parse a string for the raw tokens.
94
94
  */
95
95
  export function parse(str, { prefixes = "./", delimiter = "/#?" } = {}) {
96
- var tokens = lexer(str)
96
+ var tokens = lexer(str);
97
97
 
98
- var defaultPattern = "[^".concat(escapeString(delimiter), "]+?")
99
- var result = []
100
- var key = 0
101
- var i = 0
102
- var path = ""
98
+ var defaultPattern = "[^".concat(escapeString(delimiter), "]+?");
99
+ var result = [];
100
+ var key = 0;
101
+ var i = 0;
102
+ var path = "";
103
103
  var tryConsume = function (type) {
104
- if (i < tokens.length && tokens[i].type === type) return tokens[i++].value
105
- return undefined
106
- }
104
+ if (i < tokens.length && tokens[i].type === type) return tokens[i++].value;
105
+ return undefined;
106
+ };
107
107
  var mustConsume = function (type) {
108
- var value = tryConsume(type)
109
- if (value !== undefined) return value
110
- var _a = tokens[i]
111
- var nextType = _a.type
112
- var index = _a.inde
108
+ var value = tryConsume(type);
109
+ if (value !== undefined) return value;
110
+ var _a = tokens[i];
111
+ var nextType = _a.type;
112
+ var index = _a.inde;
113
113
  throw new TypeError(
114
114
  "Unexpected "
115
115
  .concat(nextType, " at ")
116
116
  .concat(index, ", expected ")
117
117
  .concat(type),
118
- )
119
- }
118
+ );
119
+ };
120
120
  var consumeText = function () {
121
- var result = ""
122
- var value
121
+ var result = "";
122
+ var value;
123
123
  while ((value = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR"))) {
124
- result += value
124
+ result += value;
125
125
  }
126
- return result
127
- }
126
+ return result;
127
+ };
128
128
  while (i < tokens.length) {
129
- var char = tryConsume("CHAR")
130
- var name = tryConsume("NAME")
131
- var pattern = tryConsume("PATTERN")
129
+ var char = tryConsume("CHAR");
130
+ var name = tryConsume("NAME");
131
+ var pattern = tryConsume("PATTERN");
132
132
  if (name || pattern) {
133
- let prefix = char || ""
133
+ let prefix = char || "";
134
134
  if (prefixes.indexOf(prefix) === -1) {
135
- path += prefix
136
- prefix = ""
135
+ path += prefix;
136
+ prefix = "";
137
137
  }
138
138
  if (path) {
139
- result.push(path)
140
- path = ""
139
+ result.push(path);
140
+ path = "";
141
141
  }
142
142
  result.push({
143
143
  name: name || key++,
@@ -145,43 +145,43 @@ export function parse(str, { prefixes = "./", delimiter = "/#?" } = {}) {
145
145
  suffix: "",
146
146
  pattern: pattern || defaultPattern,
147
147
  modifier: tryConsume("MODIFIER") || "",
148
- })
149
- continue
148
+ });
149
+ continue;
150
150
  }
151
- var value = char || tryConsume("ESCAPED_CHAR")
151
+ var value = char || tryConsume("ESCAPED_CHAR");
152
152
  if (value) {
153
- path += value
154
- continue
153
+ path += value;
154
+ continue;
155
155
  }
156
156
  if (path) {
157
- result.push(path)
158
- path = ""
157
+ result.push(path);
158
+ path = "";
159
159
  }
160
- var open = tryConsume("OPEN")
160
+ var open = tryConsume("OPEN");
161
161
  if (open) {
162
- var prefix = consumeText()
163
- var name_1 = tryConsume("NAME") || ""
164
- var pattern_1 = tryConsume("PATTERN") || ""
165
- var suffix = consumeText()
166
- mustConsume("CLOSE")
162
+ var prefix = consumeText();
163
+ var name_1 = tryConsume("NAME") || "";
164
+ var pattern_1 = tryConsume("PATTERN") || "";
165
+ var suffix = consumeText();
166
+ mustConsume("CLOSE");
167
167
  result.push({
168
168
  name: name_1 || (pattern_1 ? key++ : ""),
169
169
  pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
170
170
  prefix,
171
171
  suffix,
172
172
  modifier: tryConsume("MODIFIER") || "",
173
- })
174
- continue
173
+ });
174
+ continue;
175
175
  }
176
- mustConsume("END")
176
+ mustConsume("END");
177
177
  }
178
- return result
178
+ return result;
179
179
  }
180
180
  /**
181
181
  * Compile a string to a template function for the path.
182
182
  */
183
183
  export function compile(str, options) {
184
- return tokensToFunction(parse(str, options), options)
184
+ return tokensToFunction(parse(str, options), options);
185
185
  }
186
186
  /**
187
187
  * Expose a method for transforming tokens into the path function.
@@ -196,21 +196,21 @@ export function tokensToFunction(
196
196
  return new RegExp(
197
197
  "^(?:".concat(token.pattern, ")$"),
198
198
  sensitive ? "" : "i",
199
- )
199
+ );
200
200
  }
201
- return undefined
202
- })
201
+ return undefined;
202
+ });
203
203
  return function (data) {
204
- var path = ""
204
+ var path = "";
205
205
  for (var i = 0; i < tokens.length; i++) {
206
- var token = tokens[i]
206
+ var token = tokens[i];
207
207
  if (typeof token === "string") {
208
- path += token
209
- continue
208
+ path += token;
209
+ continue;
210
210
  }
211
- var value = data ? data[token.name] : undefined
212
- var optional = token.modifier === "?" || token.modifier === "*"
213
- var repeat = token.modifier === "*" || token.modifier === "+"
211
+ var value = data ? data[token.name] : undefined;
212
+ var optional = token.modifier === "?" || token.modifier === "*";
213
+ var repeat = token.modifier === "*" || token.modifier === "+";
214
214
  if (Array.isArray(value)) {
215
215
  if (!repeat) {
216
216
  throw new TypeError(
@@ -218,102 +218,102 @@ export function tokensToFunction(
218
218
  token.name,
219
219
  '" to not repeat, but got an array',
220
220
  ),
221
- )
221
+ );
222
222
  }
223
223
  if (value.length === 0) {
224
- if (optional) continue
224
+ if (optional) continue;
225
225
  throw new TypeError(
226
226
  'Expected "'.concat(token.name, '" to not be empty'),
227
- )
227
+ );
228
228
  }
229
229
  for (var j = 0; j < value.length; j++) {
230
- let segment = encode(value[j], token)
230
+ let segment = encode(value[j], token);
231
231
  if (validate && !matches[i].test(segment)) {
232
232
  throw new TypeError(
233
233
  'Expected all "'
234
234
  .concat(token.name, '" to match "')
235
235
  .concat(token.pattern, '", but got "')
236
236
  .concat(segment, '"'),
237
- )
237
+ );
238
238
  }
239
- path += token.prefix + segment + token.suffix
239
+ path += token.prefix + segment + token.suffix;
240
240
  }
241
- continue
241
+ continue;
242
242
  }
243
243
  if (typeof value === "string" || typeof value === "number") {
244
- var segment = encode(String(value), token)
244
+ var segment = encode(String(value), token);
245
245
  if (validate && !matches[i].test(segment)) {
246
246
  throw new TypeError(
247
247
  'Expected "'
248
248
  .concat(token.name, '" to match "')
249
249
  .concat(token.pattern, '", but got "')
250
250
  .concat(segment, '"'),
251
- )
251
+ );
252
252
  }
253
- path += token.prefix + segment + token.suffix
254
- continue
253
+ path += token.prefix + segment + token.suffix;
254
+ continue;
255
255
  }
256
- if (optional) continue
257
- var typeOfMessage = repeat ? "an array" : "a string"
256
+ if (optional) continue;
257
+ var typeOfMessage = repeat ? "an array" : "a string";
258
258
  throw new TypeError(
259
259
  'Expected "'.concat(token.name, '" to be ').concat(typeOfMessage),
260
- )
260
+ );
261
261
  }
262
- return path
263
- }
262
+ return path;
263
+ };
264
264
  }
265
265
  /**
266
266
  * Create path match function from `path-to-regexp` spec.
267
267
  */
268
268
  export function match(str, options) {
269
- var keys = []
270
- var re = pathToRegexp(str, keys, options)
271
- return regexpToFunction(re, keys, options)
269
+ var keys = [];
270
+ var re = pathToRegexp(str, keys, options);
271
+ return regexpToFunction(re, keys, options);
272
272
  }
273
273
  /**
274
274
  * Create a path match function from `path-to-regexp` output.
275
275
  */
276
276
  export function regexpToFunction(re, keys, { decode = (x) => x }) {
277
277
  return function (pathname) {
278
- var m = re.exec(pathname)
279
- if (!m) return false
280
- var path = m[0]
281
- var index = m.index
282
- var params = Object.create(null)
278
+ var m = re.exec(pathname);
279
+ if (!m) return false;
280
+ var path = m[0];
281
+ var index = m.index;
282
+ var params = Object.create(null);
283
283
  var _loop_1 = function (i) {
284
- if (m[i] === undefined) return "continue"
285
- var key = keys[i - 1]
284
+ if (m[i] === undefined) return "continue";
285
+ var key = keys[i - 1];
286
286
  if (key.modifier === "*" || key.modifier === "+") {
287
287
  params[key.name] = m[i]
288
288
  .split(key.prefix + key.suffix)
289
289
  .map(function (value) {
290
- return decode(value, key)
291
- })
290
+ return decode(value, key);
291
+ });
292
292
  } else {
293
- params[key.name] = decode(m[i], key)
293
+ params[key.name] = decode(m[i], key);
294
294
  }
295
- return undefined
296
- }
295
+ return undefined;
296
+ };
297
297
  for (var i = 1; i < m.length; i++) {
298
- _loop_1(i)
298
+ _loop_1(i);
299
299
  }
300
- return { path, index, params }
301
- }
300
+ return { path, index, params };
301
+ };
302
302
  }
303
303
  /**
304
304
  * Escape a regular expression string.
305
305
  */
306
306
  function escapeString(str) {
307
- return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1")
307
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
308
308
  }
309
309
  /**
310
310
  * Pull out keys from a regexp.
311
311
  */
312
312
  function regexpToRegexp(path, keys) {
313
- if (!keys) return path
314
- var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g
315
- var index = 0
316
- var execResult = groupsRegex.exec(path.source)
313
+ if (!keys) return path;
314
+ var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
315
+ var index = 0;
316
+ var execResult = groupsRegex.exec(path.source);
317
317
  while (execResult) {
318
318
  keys.push({
319
319
  // Use parenthesized substring match if available, index otherwise
@@ -322,25 +322,25 @@ function regexpToRegexp(path, keys) {
322
322
  suffix: "",
323
323
  modifier: "",
324
324
  pattern: "",
325
- })
326
- execResult = groupsRegex.exec(path.source)
325
+ });
326
+ execResult = groupsRegex.exec(path.source);
327
327
  }
328
- return path
328
+ return path;
329
329
  }
330
330
  /**
331
331
  * Transform an array into a regexp.
332
332
  */
333
333
  function arrayToRegexp(paths, keys, { sensitive }) {
334
334
  var parts = paths.map(function (path) {
335
- return pathToRegexp(path, keys, { sensitive }).source
336
- })
337
- return new RegExp("(?:".concat(parts.join("|"), ")"), sensitive ? "" : "i")
335
+ return pathToRegexp(path, keys, { sensitive }).source;
336
+ });
337
+ return new RegExp("(?:".concat(parts.join("|"), ")"), sensitive ? "" : "i");
338
338
  }
339
339
  /**
340
340
  * Create a path regexp from string input.
341
341
  */
342
342
  function stringToRegexp(path, keys, options) {
343
- return tokensToRegexp(parse(path, options), keys, options)
343
+ return tokensToRegexp(parse(path, options), keys, options);
344
344
  }
345
345
  /**
346
346
  * Expose a function for taking tokens and returning a RegExp.
@@ -358,22 +358,22 @@ export function tokensToRegexp(
358
358
  endsWith = "",
359
359
  } = {},
360
360
  ) {
361
- var endsWithRe = "[".concat(escapeString(endsWith), "]|$")
362
- var delimiterRe = "[".concat(escapeString(delimiter), "]")
363
- var route = start ? "^" : ""
361
+ var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
362
+ var delimiterRe = "[".concat(escapeString(delimiter), "]");
363
+ var route = start ? "^" : "";
364
364
  // Iterate over the tokens and create our regexp string.
365
365
  for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
366
- var token = tokens_1[_i]
366
+ var token = tokens_1[_i];
367
367
  if (typeof token === "string") {
368
- route += escapeString(encode(token))
368
+ route += escapeString(encode(token));
369
369
  } else {
370
- var prefix = escapeString(encode(token.prefix))
371
- var suffix = escapeString(encode(token.suffix))
370
+ var prefix = escapeString(encode(token.prefix));
371
+ var suffix = escapeString(encode(token.suffix));
372
372
  if (token.pattern) {
373
- if (keys) keys.push(token)
373
+ if (keys) keys.push(token);
374
374
  if (prefix || suffix) {
375
375
  if (token.modifier === "+" || token.modifier === "*") {
376
- var mod = token.modifier === "*" ? "?" : ""
376
+ var mod = token.modifier === "*" ? "?" : "";
377
377
  route += "(?:"
378
378
  .concat(prefix, "((?:")
379
379
  .concat(token.pattern, ")(?:")
@@ -381,41 +381,46 @@ export function tokensToRegexp(
381
381
  .concat(prefix, "(?:")
382
382
  .concat(token.pattern, "))*)")
383
383
  .concat(suffix, ")")
384
- .concat(mod)
384
+ .concat(mod);
385
385
  } else {
386
386
  route += "(?:"
387
387
  .concat(prefix, "(")
388
388
  .concat(token.pattern, ")")
389
389
  .concat(suffix, ")")
390
- .concat(token.modifier)
390
+ .concat(token.modifier);
391
391
  }
392
392
  } else if (token.modifier === "+" || token.modifier === "*") {
393
- route += "((?:".concat(token.pattern, ")").concat(token.modifier, ")")
393
+ route += "((?:"
394
+ .concat(token.pattern, ")")
395
+ .concat(token.modifier, ")");
394
396
  } else {
395
- route += "(".concat(token.pattern, ")").concat(token.modifier)
397
+ route += "(".concat(token.pattern, ")").concat(token.modifier);
396
398
  }
397
399
  } else {
398
- route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier)
400
+ route += "(?:"
401
+ .concat(prefix)
402
+ .concat(suffix, ")")
403
+ .concat(token.modifier);
399
404
  }
400
405
  }
401
406
  }
402
407
  if (end) {
403
- if (!strict) route += "".concat(delimiterRe, "?")
404
- route += endsWith ? "(?=".concat(endsWithRe, ")") : "$"
408
+ if (!strict) route += "".concat(delimiterRe, "?");
409
+ route += endsWith ? "(?=".concat(endsWithRe, ")") : "$";
405
410
  } else {
406
- var endToken = tokens[tokens.length - 1]
411
+ var endToken = tokens[tokens.length - 1];
407
412
  var isEndDelimited =
408
413
  typeof endToken === "string"
409
414
  ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1
410
- : endToken === undefined
415
+ : endToken === undefined;
411
416
  if (!strict) {
412
- route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?")
417
+ route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
413
418
  }
414
419
  if (!isEndDelimited) {
415
- route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")")
420
+ route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
416
421
  }
417
422
  }
418
- return new RegExp(route, sensitive ? "" : "i")
423
+ return new RegExp(route, sensitive ? "" : "i");
419
424
  }
420
425
  /**
421
426
  * Normalize the given path string, returning a regular expression.
@@ -425,7 +430,7 @@ export function tokensToRegexp(
425
430
  * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
426
431
  */
427
432
  export function pathToRegexp(path, keys, options) {
428
- if (path instanceof RegExp) return regexpToRegexp(path, keys)
429
- if (Array.isArray(path)) return arrayToRegexp(path, keys, options)
430
- return stringToRegexp(path, keys, options)
433
+ if (path instanceof RegExp) return regexpToRegexp(path, keys);
434
+ if (Array.isArray(path)) return arrayToRegexp(path, keys, options);
435
+ return stringToRegexp(path, keys, options);
431
436
  }
@@ -1,22 +1,22 @@
1
- import { match } from "./path_to_regexp.js"
1
+ import { match } from "./path_to_regexp.js";
2
2
 
3
3
  export const setupRoutes = (routes) => {
4
4
  const candidates = Object.keys(routes).map((pathPattern) => {
5
5
  const applyPatternMatching = match(pathPattern, {
6
6
  decode: decodeURIComponent,
7
- })
7
+ });
8
8
  return {
9
9
  applyPatternMatching,
10
10
  requestHandler: routes[pathPattern],
11
- }
12
- })
11
+ };
12
+ });
13
13
 
14
14
  return (request, { pushResponse, redirectRequest }) => {
15
- let result
15
+ let result;
16
16
  const found = candidates.find((candidate) => {
17
- result = candidate.applyPatternMatching(request.pathname)
18
- return Boolean(result)
19
- })
17
+ result = candidate.applyPatternMatching(request.pathname);
18
+ return Boolean(result);
19
+ });
20
20
  if (found) {
21
21
  return found.requestHandler(
22
22
  {
@@ -24,8 +24,8 @@ export const setupRoutes = (routes) => {
24
24
  routeParams: result.params,
25
25
  },
26
26
  { pushResponse, redirectRequest },
27
- )
27
+ );
28
28
  }
29
- return null
30
- }
31
- }
29
+ return null;
30
+ };
31
+ };