@tanstack/router-core 1.136.4 → 1.136.5

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 (48) hide show
  1. package/dist/cjs/Matches.cjs.map +1 -1
  2. package/dist/cjs/Matches.d.cts +2 -0
  3. package/dist/cjs/index.cjs +0 -5
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/index.d.cts +1 -4
  6. package/dist/cjs/lru-cache.cjs +5 -0
  7. package/dist/cjs/lru-cache.cjs.map +1 -1
  8. package/dist/cjs/lru-cache.d.cts +1 -0
  9. package/dist/cjs/new-process-route-tree.cjs +655 -0
  10. package/dist/cjs/new-process-route-tree.cjs.map +1 -0
  11. package/dist/cjs/new-process-route-tree.d.cts +177 -0
  12. package/dist/cjs/path.cjs +133 -434
  13. package/dist/cjs/path.cjs.map +1 -1
  14. package/dist/cjs/path.d.cts +3 -39
  15. package/dist/cjs/router.cjs +47 -98
  16. package/dist/cjs/router.cjs.map +1 -1
  17. package/dist/cjs/router.d.cts +6 -11
  18. package/dist/esm/Matches.d.ts +2 -0
  19. package/dist/esm/Matches.js.map +1 -1
  20. package/dist/esm/index.d.ts +1 -4
  21. package/dist/esm/index.js +1 -6
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/lru-cache.d.ts +1 -0
  24. package/dist/esm/lru-cache.js +5 -0
  25. package/dist/esm/lru-cache.js.map +1 -1
  26. package/dist/esm/new-process-route-tree.d.ts +177 -0
  27. package/dist/esm/new-process-route-tree.js +655 -0
  28. package/dist/esm/new-process-route-tree.js.map +1 -0
  29. package/dist/esm/path.d.ts +3 -39
  30. package/dist/esm/path.js +133 -434
  31. package/dist/esm/path.js.map +1 -1
  32. package/dist/esm/router.d.ts +6 -11
  33. package/dist/esm/router.js +48 -99
  34. package/dist/esm/router.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/Matches.ts +2 -0
  37. package/src/index.ts +0 -6
  38. package/src/lru-cache.ts +6 -0
  39. package/src/new-process-route-tree.ts +1036 -0
  40. package/src/path.ts +168 -639
  41. package/src/router.ts +57 -126
  42. package/dist/cjs/process-route-tree.cjs +0 -144
  43. package/dist/cjs/process-route-tree.cjs.map +0 -1
  44. package/dist/cjs/process-route-tree.d.cts +0 -18
  45. package/dist/esm/process-route-tree.d.ts +0 -18
  46. package/dist/esm/process-route-tree.js +0 -144
  47. package/dist/esm/process-route-tree.js.map +0 -1
  48. package/src/process-route-tree.ts +0 -241
package/dist/cjs/path.cjs CHANGED
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const utils = require("./utils.cjs");
4
- const SEGMENT_TYPE_PATHNAME = 0;
5
- const SEGMENT_TYPE_PARAM = 1;
6
- const SEGMENT_TYPE_WILDCARD = 2;
7
- const SEGMENT_TYPE_OPTIONAL_PARAM = 3;
4
+ const newProcessRouteTree = require("./new-process-route-tree.cjs");
8
5
  function joinPaths(paths) {
9
6
  return cleanPath(
10
7
  paths.filter((val) => {
@@ -33,247 +30,168 @@ function removeTrailingSlash(value, basepath) {
33
30
  function exactPathTest(pathName1, pathName2, basepath) {
34
31
  return removeTrailingSlash(pathName1, basepath) === removeTrailingSlash(pathName2, basepath);
35
32
  }
36
- function segmentToString(segment) {
37
- const { type, value } = segment;
38
- if (type === SEGMENT_TYPE_PATHNAME) {
39
- return value;
40
- }
41
- const { prefixSegment, suffixSegment } = segment;
42
- if (type === SEGMENT_TYPE_PARAM) {
43
- const param = value.substring(1);
44
- if (prefixSegment && suffixSegment) {
45
- return `${prefixSegment}{$${param}}${suffixSegment}`;
46
- } else if (prefixSegment) {
47
- return `${prefixSegment}{$${param}}`;
48
- } else if (suffixSegment) {
49
- return `{$${param}}${suffixSegment}`;
50
- }
51
- }
52
- if (type === SEGMENT_TYPE_OPTIONAL_PARAM) {
53
- const param = value.substring(1);
54
- if (prefixSegment && suffixSegment) {
55
- return `${prefixSegment}{-$${param}}${suffixSegment}`;
56
- } else if (prefixSegment) {
57
- return `${prefixSegment}{-$${param}}`;
58
- } else if (suffixSegment) {
59
- return `{-$${param}}${suffixSegment}`;
60
- }
61
- return `{-$${param}}`;
62
- }
63
- if (type === SEGMENT_TYPE_WILDCARD) {
64
- if (prefixSegment && suffixSegment) {
65
- return `${prefixSegment}{$}${suffixSegment}`;
66
- } else if (prefixSegment) {
67
- return `${prefixSegment}{$}`;
68
- } else if (suffixSegment) {
69
- return `{$}${suffixSegment}`;
70
- }
71
- }
72
- return value;
73
- }
74
33
  function resolvePath({
75
34
  base,
76
35
  to,
77
36
  trailingSlash = "never",
78
- parseCache
37
+ cache
79
38
  }) {
80
- let baseSegments = parsePathname(base, parseCache).slice();
81
- const toSegments = parsePathname(to, parseCache);
82
- if (baseSegments.length > 1 && utils.last(baseSegments)?.value === "/") {
83
- baseSegments.pop();
39
+ const isAbsolute = to.startsWith("/");
40
+ const isBase = !isAbsolute && to === ".";
41
+ let key;
42
+ if (cache) {
43
+ key = isAbsolute ? to : isBase ? base : base + "\0" + to;
44
+ const cached = cache.get(key);
45
+ if (cached) return cached;
84
46
  }
85
- for (let index = 0, length = toSegments.length; index < length; index++) {
86
- const toSegment = toSegments[index];
87
- const value = toSegment.value;
88
- if (value === "/") {
89
- if (!index) {
90
- baseSegments = [toSegment];
91
- } else if (index === length - 1) {
92
- baseSegments.push(toSegment);
93
- } else ;
94
- } else if (value === "..") {
47
+ let baseSegments;
48
+ if (isBase) {
49
+ baseSegments = base.split("/");
50
+ } else if (isAbsolute) {
51
+ baseSegments = to.split("/");
52
+ } else {
53
+ baseSegments = base.split("/");
54
+ while (baseSegments.length > 1 && utils.last(baseSegments) === "") {
95
55
  baseSegments.pop();
96
- } else if (value === ".") ;
97
- else {
98
- baseSegments.push(toSegment);
56
+ }
57
+ const toSegments = to.split("/");
58
+ for (let index = 0, length = toSegments.length; index < length; index++) {
59
+ const value = toSegments[index];
60
+ if (value === "") {
61
+ if (!index) {
62
+ baseSegments = [value];
63
+ } else if (index === length - 1) {
64
+ baseSegments.push(value);
65
+ } else ;
66
+ } else if (value === "..") {
67
+ baseSegments.pop();
68
+ } else if (value === ".") ;
69
+ else {
70
+ baseSegments.push(value);
71
+ }
99
72
  }
100
73
  }
101
74
  if (baseSegments.length > 1) {
102
- if (utils.last(baseSegments).value === "/") {
75
+ if (utils.last(baseSegments) === "") {
103
76
  if (trailingSlash === "never") {
104
77
  baseSegments.pop();
105
78
  }
106
79
  } else if (trailingSlash === "always") {
107
- baseSegments.push({ type: SEGMENT_TYPE_PATHNAME, value: "/" });
80
+ baseSegments.push("");
108
81
  }
109
82
  }
110
- const segmentValues = baseSegments.map(segmentToString);
111
- const joined = joinPaths(segmentValues);
112
- return joined;
113
- }
114
- const parsePathname = (pathname, cache) => {
115
- if (!pathname) return [];
116
- const cached = cache?.get(pathname);
117
- if (cached) return cached;
118
- const parsed = baseParsePathname(pathname);
119
- cache?.set(pathname, parsed);
120
- return parsed;
121
- };
122
- const PARAM_RE = /^\$.{1,}$/;
123
- const PARAM_W_CURLY_BRACES_RE = /^(.*?)\{(\$[a-zA-Z_$][a-zA-Z0-9_$]*)\}(.*)$/;
124
- const OPTIONAL_PARAM_W_CURLY_BRACES_RE = /^(.*?)\{-(\$[a-zA-Z_$][a-zA-Z0-9_$]*)\}(.*)$/;
125
- const WILDCARD_RE = /^\$$/;
126
- const WILDCARD_W_CURLY_BRACES_RE = /^(.*?)\{\$\}(.*)$/;
127
- function baseParsePathname(pathname) {
128
- pathname = cleanPath(pathname);
129
- const segments = [];
130
- if (pathname.slice(0, 1) === "/") {
131
- pathname = pathname.substring(1);
132
- segments.push({
133
- type: SEGMENT_TYPE_PATHNAME,
134
- value: "/"
135
- });
136
- }
137
- if (!pathname) {
138
- return segments;
83
+ let segment;
84
+ let joined = "";
85
+ for (let i = 0; i < baseSegments.length; i++) {
86
+ if (i > 0) joined += "/";
87
+ const part = baseSegments[i];
88
+ if (!part) continue;
89
+ segment = newProcessRouteTree.parseSegment(part, 0, segment);
90
+ const kind = segment[0];
91
+ if (kind === newProcessRouteTree.SEGMENT_TYPE_PATHNAME) {
92
+ joined += part;
93
+ continue;
94
+ }
95
+ const end = segment[5];
96
+ const prefix = part.substring(0, segment[1]);
97
+ const suffix = part.substring(segment[4], end);
98
+ const value = part.substring(segment[2], segment[3]);
99
+ if (kind === newProcessRouteTree.SEGMENT_TYPE_PARAM) {
100
+ joined += prefix || suffix ? `${prefix}{$${value}}${suffix}` : `$${value}`;
101
+ } else if (kind === newProcessRouteTree.SEGMENT_TYPE_WILDCARD) {
102
+ joined += prefix || suffix ? `${prefix}{$}${suffix}` : "$";
103
+ } else {
104
+ joined += `${prefix}{-$${value}}${suffix}`;
105
+ }
139
106
  }
140
- const split = pathname.split("/").filter(Boolean);
141
- segments.push(
142
- ...split.map((part) => {
143
- const wildcardBracesMatch = part.match(WILDCARD_W_CURLY_BRACES_RE);
144
- if (wildcardBracesMatch) {
145
- const prefix = wildcardBracesMatch[1];
146
- const suffix = wildcardBracesMatch[2];
147
- return {
148
- type: SEGMENT_TYPE_WILDCARD,
149
- value: "$",
150
- prefixSegment: prefix || void 0,
151
- suffixSegment: suffix || void 0
152
- };
153
- }
154
- const optionalParamBracesMatch = part.match(
155
- OPTIONAL_PARAM_W_CURLY_BRACES_RE
156
- );
157
- if (optionalParamBracesMatch) {
158
- const prefix = optionalParamBracesMatch[1];
159
- const paramName = optionalParamBracesMatch[2];
160
- const suffix = optionalParamBracesMatch[3];
161
- return {
162
- type: SEGMENT_TYPE_OPTIONAL_PARAM,
163
- value: paramName,
164
- // Now just $paramName (no prefix)
165
- prefixSegment: prefix || void 0,
166
- suffixSegment: suffix || void 0
167
- };
168
- }
169
- const paramBracesMatch = part.match(PARAM_W_CURLY_BRACES_RE);
170
- if (paramBracesMatch) {
171
- const prefix = paramBracesMatch[1];
172
- const paramName = paramBracesMatch[2];
173
- const suffix = paramBracesMatch[3];
174
- return {
175
- type: SEGMENT_TYPE_PARAM,
176
- value: "" + paramName,
177
- prefixSegment: prefix || void 0,
178
- suffixSegment: suffix || void 0
179
- };
180
- }
181
- if (PARAM_RE.test(part)) {
182
- const paramName = part.substring(1);
183
- return {
184
- type: SEGMENT_TYPE_PARAM,
185
- value: "$" + paramName,
186
- prefixSegment: void 0,
187
- suffixSegment: void 0
188
- };
189
- }
190
- if (WILDCARD_RE.test(part)) {
191
- return {
192
- type: SEGMENT_TYPE_WILDCARD,
193
- value: "$",
194
- prefixSegment: void 0,
195
- suffixSegment: void 0
196
- };
197
- }
198
- return {
199
- type: SEGMENT_TYPE_PATHNAME,
200
- value: part
201
- };
202
- })
203
- );
204
- if (pathname.slice(-1) === "/") {
205
- pathname = pathname.substring(1);
206
- segments.push({
207
- type: SEGMENT_TYPE_PATHNAME,
208
- value: "/"
209
- });
107
+ joined = cleanPath(joined);
108
+ const result = joined || "/";
109
+ if (key && cache) cache.set(key, result);
110
+ return result;
111
+ }
112
+ function encodeParam(key, params, decodeCharMap) {
113
+ const value = params[key];
114
+ if (typeof value !== "string") return value;
115
+ if (key === "_splat") {
116
+ return encodeURI(value);
117
+ } else {
118
+ return encodePathParam(value, decodeCharMap);
210
119
  }
211
- return segments;
212
120
  }
213
121
  function interpolatePath({
214
122
  path,
215
123
  params,
216
- decodeCharMap,
217
- parseCache
124
+ decodeCharMap
218
125
  }) {
219
- const interpolatedPathSegments = parsePathname(path, parseCache);
220
- function encodeParam(key) {
221
- const value = params[key];
222
- const isValueString = typeof value === "string";
223
- if (key === "*" || key === "_splat") {
224
- return isValueString ? encodeURI(value) : value;
225
- } else {
226
- return isValueString ? encodePathParam(value, decodeCharMap) : value;
227
- }
228
- }
229
126
  let isMissingParams = false;
230
127
  const usedParams = {};
231
- const interpolatedPath = joinPaths(
232
- interpolatedPathSegments.map((segment) => {
233
- if (segment.type === SEGMENT_TYPE_PATHNAME) {
234
- return segment.value;
235
- }
236
- if (segment.type === SEGMENT_TYPE_WILDCARD) {
237
- usedParams._splat = params._splat;
238
- usedParams["*"] = params._splat;
239
- const segmentPrefix = segment.prefixSegment || "";
240
- const segmentSuffix = segment.suffixSegment || "";
241
- if (!params._splat) {
242
- isMissingParams = true;
243
- if (segmentPrefix || segmentSuffix) {
244
- return `${segmentPrefix}${segmentSuffix}`;
245
- }
246
- return void 0;
128
+ if (!path || path === "/")
129
+ return { interpolatedPath: "/", usedParams, isMissingParams };
130
+ if (!path.includes("$"))
131
+ return { interpolatedPath: path, usedParams, isMissingParams };
132
+ const length = path.length;
133
+ let cursor = 0;
134
+ let segment;
135
+ let joined = "";
136
+ while (cursor < length) {
137
+ const start = cursor;
138
+ segment = newProcessRouteTree.parseSegment(path, start, segment);
139
+ const end = segment[5];
140
+ cursor = end + 1;
141
+ if (start === end) continue;
142
+ const kind = segment[0];
143
+ if (kind === newProcessRouteTree.SEGMENT_TYPE_PATHNAME) {
144
+ joined += "/" + path.substring(start, end);
145
+ continue;
146
+ }
147
+ if (kind === newProcessRouteTree.SEGMENT_TYPE_WILDCARD) {
148
+ const splat = params._splat;
149
+ usedParams._splat = splat;
150
+ usedParams["*"] = splat;
151
+ const prefix = path.substring(start, segment[1]);
152
+ const suffix = path.substring(segment[4], end);
153
+ if (!splat) {
154
+ isMissingParams = true;
155
+ if (prefix || suffix) {
156
+ joined += "/" + prefix + suffix;
247
157
  }
248
- const value = encodeParam("_splat");
249
- return `${segmentPrefix}${value}${segmentSuffix}`;
158
+ continue;
250
159
  }
251
- if (segment.type === SEGMENT_TYPE_PARAM) {
252
- const key = segment.value.substring(1);
253
- if (!isMissingParams && !(key in params)) {
254
- isMissingParams = true;
255
- }
256
- usedParams[key] = params[key];
257
- const segmentPrefix = segment.prefixSegment || "";
258
- const segmentSuffix = segment.suffixSegment || "";
259
- return `${segmentPrefix}${encodeParam(key) ?? "undefined"}${segmentSuffix}`;
160
+ const value = encodeParam("_splat", params, decodeCharMap);
161
+ joined += "/" + prefix + value + suffix;
162
+ continue;
163
+ }
164
+ if (kind === newProcessRouteTree.SEGMENT_TYPE_PARAM) {
165
+ const key = path.substring(segment[2], segment[3]);
166
+ if (!isMissingParams && !(key in params)) {
167
+ isMissingParams = true;
260
168
  }
261
- if (segment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
262
- const key = segment.value.substring(1);
263
- const segmentPrefix = segment.prefixSegment || "";
264
- const segmentSuffix = segment.suffixSegment || "";
265
- if (!(key in params) || params[key] == null) {
266
- if (segmentPrefix || segmentSuffix) {
267
- return `${segmentPrefix}${segmentSuffix}`;
268
- }
269
- return void 0;
169
+ usedParams[key] = params[key];
170
+ const prefix = path.substring(start, segment[1]);
171
+ const suffix = path.substring(segment[4], end);
172
+ const value = encodeParam(key, params, decodeCharMap) ?? "undefined";
173
+ joined += "/" + prefix + value + suffix;
174
+ continue;
175
+ }
176
+ if (kind === newProcessRouteTree.SEGMENT_TYPE_OPTIONAL_PARAM) {
177
+ const key = path.substring(segment[2], segment[3]);
178
+ const prefix = path.substring(start, segment[1]);
179
+ const suffix = path.substring(segment[4], end);
180
+ const valueRaw = params[key];
181
+ if (valueRaw == null) {
182
+ if (prefix || suffix) {
183
+ joined += "/" + prefix + suffix;
270
184
  }
271
- usedParams[key] = params[key];
272
- return `${segmentPrefix}${encodeParam(key) ?? ""}${segmentSuffix}`;
185
+ continue;
273
186
  }
274
- return segment.value;
275
- })
276
- );
187
+ usedParams[key] = valueRaw;
188
+ const value = encodeParam(key, params, decodeCharMap) ?? "";
189
+ joined += "/" + prefix + value + suffix;
190
+ continue;
191
+ }
192
+ }
193
+ if (path.endsWith("/")) joined += "/";
194
+ const interpolatedPath = joined || "/";
277
195
  return { usedParams, interpolatedPath, isMissingParams };
278
196
  }
279
197
  function encodePathParam(value, decodeCharMap) {
@@ -285,229 +203,10 @@ function encodePathParam(value, decodeCharMap) {
285
203
  }
286
204
  return encoded;
287
205
  }
288
- function matchPathname(currentPathname, matchLocation, parseCache) {
289
- const pathParams = matchByPath(currentPathname, matchLocation, parseCache);
290
- if (matchLocation.to && !pathParams) {
291
- return;
292
- }
293
- return pathParams ?? {};
294
- }
295
- function matchByPath(from, {
296
- to,
297
- fuzzy,
298
- caseSensitive
299
- }, parseCache) {
300
- const stringTo = to;
301
- const baseSegments = parsePathname(
302
- from.startsWith("/") ? from : `/${from}`,
303
- parseCache
304
- );
305
- const routeSegments = parsePathname(
306
- stringTo.startsWith("/") ? stringTo : `/${stringTo}`,
307
- parseCache
308
- );
309
- const params = {};
310
- const result = isMatch(
311
- baseSegments,
312
- routeSegments,
313
- params,
314
- fuzzy,
315
- caseSensitive
316
- );
317
- return result ? params : void 0;
318
- }
319
- function isMatch(baseSegments, routeSegments, params, fuzzy, caseSensitive) {
320
- let baseIndex = 0;
321
- let routeIndex = 0;
322
- while (baseIndex < baseSegments.length || routeIndex < routeSegments.length) {
323
- const baseSegment = baseSegments[baseIndex];
324
- const routeSegment = routeSegments[routeIndex];
325
- if (routeSegment) {
326
- if (routeSegment.type === SEGMENT_TYPE_WILDCARD) {
327
- const remainingBaseSegments = baseSegments.slice(baseIndex);
328
- let _splat;
329
- if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
330
- if (!baseSegment) return false;
331
- const prefix = routeSegment.prefixSegment || "";
332
- const suffix = routeSegment.suffixSegment || "";
333
- const baseValue = baseSegment.value;
334
- if ("prefixSegment" in routeSegment) {
335
- if (!baseValue.startsWith(prefix)) {
336
- return false;
337
- }
338
- }
339
- if ("suffixSegment" in routeSegment) {
340
- if (!baseSegments[baseSegments.length - 1]?.value.endsWith(suffix)) {
341
- return false;
342
- }
343
- }
344
- let rejoinedSplat = decodeURI(
345
- joinPaths(remainingBaseSegments.map((d) => d.value))
346
- );
347
- if (prefix && rejoinedSplat.startsWith(prefix)) {
348
- rejoinedSplat = rejoinedSplat.slice(prefix.length);
349
- }
350
- if (suffix && rejoinedSplat.endsWith(suffix)) {
351
- rejoinedSplat = rejoinedSplat.slice(
352
- 0,
353
- rejoinedSplat.length - suffix.length
354
- );
355
- }
356
- _splat = rejoinedSplat;
357
- } else {
358
- _splat = decodeURI(
359
- joinPaths(remainingBaseSegments.map((d) => d.value))
360
- );
361
- }
362
- params["*"] = _splat;
363
- params["_splat"] = _splat;
364
- return true;
365
- }
366
- if (routeSegment.type === SEGMENT_TYPE_PATHNAME) {
367
- if (routeSegment.value === "/" && !baseSegment?.value) {
368
- routeIndex++;
369
- continue;
370
- }
371
- if (baseSegment) {
372
- if (caseSensitive) {
373
- if (routeSegment.value !== baseSegment.value) {
374
- return false;
375
- }
376
- } else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
377
- return false;
378
- }
379
- baseIndex++;
380
- routeIndex++;
381
- continue;
382
- } else {
383
- return false;
384
- }
385
- }
386
- if (routeSegment.type === SEGMENT_TYPE_PARAM) {
387
- if (!baseSegment) {
388
- return false;
389
- }
390
- if (baseSegment.value === "/") {
391
- return false;
392
- }
393
- let _paramValue = "";
394
- let matched = false;
395
- if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
396
- const prefix = routeSegment.prefixSegment || "";
397
- const suffix = routeSegment.suffixSegment || "";
398
- const baseValue = baseSegment.value;
399
- if (prefix && !baseValue.startsWith(prefix)) {
400
- return false;
401
- }
402
- if (suffix && !baseValue.endsWith(suffix)) {
403
- return false;
404
- }
405
- let paramValue = baseValue;
406
- if (prefix && paramValue.startsWith(prefix)) {
407
- paramValue = paramValue.slice(prefix.length);
408
- }
409
- if (suffix && paramValue.endsWith(suffix)) {
410
- paramValue = paramValue.slice(0, paramValue.length - suffix.length);
411
- }
412
- _paramValue = decodeURIComponent(paramValue);
413
- matched = true;
414
- } else {
415
- _paramValue = decodeURIComponent(baseSegment.value);
416
- matched = true;
417
- }
418
- if (matched) {
419
- params[routeSegment.value.substring(1)] = _paramValue;
420
- baseIndex++;
421
- }
422
- routeIndex++;
423
- continue;
424
- }
425
- if (routeSegment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
426
- if (!baseSegment) {
427
- routeIndex++;
428
- continue;
429
- }
430
- if (baseSegment.value === "/") {
431
- routeIndex++;
432
- continue;
433
- }
434
- let _paramValue = "";
435
- let matched = false;
436
- if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
437
- const prefix = routeSegment.prefixSegment || "";
438
- const suffix = routeSegment.suffixSegment || "";
439
- const baseValue = baseSegment.value;
440
- if ((!prefix || baseValue.startsWith(prefix)) && (!suffix || baseValue.endsWith(suffix))) {
441
- let paramValue = baseValue;
442
- if (prefix && paramValue.startsWith(prefix)) {
443
- paramValue = paramValue.slice(prefix.length);
444
- }
445
- if (suffix && paramValue.endsWith(suffix)) {
446
- paramValue = paramValue.slice(
447
- 0,
448
- paramValue.length - suffix.length
449
- );
450
- }
451
- _paramValue = decodeURIComponent(paramValue);
452
- matched = true;
453
- }
454
- } else {
455
- let shouldMatchOptional = true;
456
- for (let lookAhead = routeIndex + 1; lookAhead < routeSegments.length; lookAhead++) {
457
- const futureRouteSegment = routeSegments[lookAhead];
458
- if (futureRouteSegment?.type === SEGMENT_TYPE_PATHNAME && futureRouteSegment.value === baseSegment.value) {
459
- shouldMatchOptional = false;
460
- break;
461
- }
462
- if (futureRouteSegment?.type === SEGMENT_TYPE_PARAM || futureRouteSegment?.type === SEGMENT_TYPE_WILDCARD) {
463
- if (baseSegments.length < routeSegments.length) {
464
- shouldMatchOptional = false;
465
- }
466
- break;
467
- }
468
- }
469
- if (shouldMatchOptional) {
470
- _paramValue = decodeURIComponent(baseSegment.value);
471
- matched = true;
472
- }
473
- }
474
- if (matched) {
475
- params[routeSegment.value.substring(1)] = _paramValue;
476
- baseIndex++;
477
- }
478
- routeIndex++;
479
- continue;
480
- }
481
- }
482
- if (baseIndex < baseSegments.length && routeIndex >= routeSegments.length) {
483
- params["**"] = joinPaths(
484
- baseSegments.slice(baseIndex).map((d) => d.value)
485
- );
486
- return !!fuzzy && routeSegments[routeSegments.length - 1]?.value !== "/";
487
- }
488
- if (routeIndex < routeSegments.length && baseIndex >= baseSegments.length) {
489
- for (let i = routeIndex; i < routeSegments.length; i++) {
490
- if (routeSegments[i]?.type !== SEGMENT_TYPE_OPTIONAL_PARAM) {
491
- return false;
492
- }
493
- }
494
- break;
495
- }
496
- break;
497
- }
498
- return true;
499
- }
500
- exports.SEGMENT_TYPE_OPTIONAL_PARAM = SEGMENT_TYPE_OPTIONAL_PARAM;
501
- exports.SEGMENT_TYPE_PARAM = SEGMENT_TYPE_PARAM;
502
- exports.SEGMENT_TYPE_PATHNAME = SEGMENT_TYPE_PATHNAME;
503
- exports.SEGMENT_TYPE_WILDCARD = SEGMENT_TYPE_WILDCARD;
504
206
  exports.cleanPath = cleanPath;
505
207
  exports.exactPathTest = exactPathTest;
506
208
  exports.interpolatePath = interpolatePath;
507
209
  exports.joinPaths = joinPaths;
508
- exports.matchByPath = matchByPath;
509
- exports.matchPathname = matchPathname;
510
- exports.parsePathname = parsePathname;
511
210
  exports.removeTrailingSlash = removeTrailingSlash;
512
211
  exports.resolvePath = resolvePath;
513
212
  exports.trimPath = trimPath;