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