@devp0nt/route0 1.0.0-next.75 → 1.0.0-next.77

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.
@@ -28,11 +28,8 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
28
28
  readonly params: _ParamsDefinition<TDefinition>;
29
29
  private _origin;
30
30
  private _callable;
31
- private _regexBaseStrictString?;
32
31
  private _regexBaseString?;
33
- private _regexStrictString?;
34
32
  private _regexString?;
35
- private _regexStrict?;
36
33
  private _regex?;
37
34
  private _regexAncestor?;
38
35
  private _captureKeys?;
@@ -54,13 +51,13 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
54
51
  *
55
52
  * If an existing route/callable route is provided, it is cloned.
56
53
  */
57
- static create<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>, config?: RouteConfigInput): CallableRoute<TDefinition>;
54
+ static create<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>, config?: RouteConfigInput): CallableRoute<NormalizeRouteDefinition<TDefinition>>;
58
55
  /**
59
56
  * Normalizes a definition/route into a callable route.
60
57
  *
61
58
  * Unlike `create`, passing a callable route returns the same instance.
62
59
  */
63
- static from<TDefinition extends string, TSearchInput extends UnknownSearchInput>(definition: TDefinition | AnyRoute<TDefinition, TSearchInput> | CallableRoute<TDefinition, TSearchInput>): CallableRoute<TDefinition, TSearchInput>;
60
+ static from<TDefinition extends string, TSearchInput extends UnknownSearchInput>(definition: TDefinition | AnyRoute<TDefinition, TSearchInput> | CallableRoute<TDefinition, TSearchInput>): CallableRoute<NormalizeRouteDefinition<TDefinition>, TSearchInput>;
64
61
  private static _getAbsPath;
65
62
  private static _getParamsDefinitionByDefinition;
66
63
  search<TNewSearchInput extends UnknownSearchInput>(): CallableRoute<TDefinition, TNewSearchInput>;
@@ -73,22 +70,17 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
73
70
  getTokens(): RouteToken[];
74
71
  /** Clones route with optional config override. */
75
72
  clone(config?: RouteConfigInput): CallableRoute<TDefinition>;
76
- get regexBaseStrictString(): string;
77
73
  get regexBaseString(): string;
78
- get regexStrictString(): string;
79
74
  get regexString(): string;
80
- get regexStrict(): RegExp;
81
75
  get regex(): RegExp;
82
76
  get regexAncestor(): RegExp;
83
77
  private get captureKeys();
84
78
  private get normalizedDefinition();
85
79
  private get definitionParts();
86
- /** Fast pathname check without building a full location object. */
80
+ /** Fast pathname exact match check without building a full location object. */
87
81
  isExactPathnameMatch(pathname: string): boolean;
88
- /** Creates a grouped strict regex pattern string from many routes. */
89
- static getRegexStrictStringGroup(routes: AnyRoute[]): string;
90
- /** Creates a strict grouped regex from many routes. */
91
- static getRegexStrictGroup(routes: AnyRoute[]): RegExp;
82
+ /** Fast pathname exact or ancestor match check without building a full location object. */
83
+ isExactOrAncestorPathnameMatch(pathname: string): boolean;
92
84
  /** Creates a grouped regex pattern string from many routes. */
93
85
  static getRegexStringGroup(routes: AnyRoute[]): string;
94
86
  /** Creates a grouped regex from many routes. */
@@ -420,8 +412,13 @@ type _RequiredParamKeys<TDefinition extends string> = {
420
412
  }[keyof _ParamsDefinition<TDefinition>];
421
413
  type ReplacePathParams<S extends string> = S extends `${infer Head}:${infer Tail}` ? Tail extends `${infer _Param}/${infer Rest}` ? ReplacePathParams<`${Head}${string}/${Rest}`> : `${Head}${string}` : S;
422
414
  type DedupeSlashes<S extends string> = S extends `${infer A}//${infer B}` ? DedupeSlashes<`${A}/${B}`> : S;
415
+ type EnsureLeadingSlash<S extends string> = S extends '' ? '/' : S extends `/${string}` ? S : `/${S}`;
416
+ type TrimTrailingSlash<S extends string> = S extends '/' ? '/' : S extends `${infer V}/` ? TrimTrailingSlash<V> : S;
417
+ type NormalizeRouteDefinition<S extends string> = TrimTrailingSlash<EnsureLeadingSlash<DedupeSlashes<S>>>;
423
418
  type EmptyRecord = Record<never, never>;
424
- type JoinPath<Parent extends string, Suffix extends string> = DedupeSlashes<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? A extends '' ? B extends '' ? '' : B extends `/${string}` ? B : `/${B}` : B extends '' ? A : A extends `${string}/` ? `${A}${B}` : B extends `/${string}` ? `${A}${B}` : `${A}/${B}` : never : never>;
419
+ type JoinPath<Parent extends string, Suffix extends string> = NormalizeRouteDefinition<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? NormalizeRouteDefinition<A> extends infer ANormalized extends string ? NormalizeRouteDefinition<B> extends infer BNormalized extends string ? BNormalized extends '/' ? ANormalized : ANormalized extends '/' ? BNormalized : `${ANormalized}/${BNormalized}` : never : never : never : never>;
420
+ type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${NormalizeRouteDefinition<JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>>}`;
421
+ type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? NormalizeRouteDefinition<TPath> : TDefinition extends `${infer TPath}*` ? NormalizeRouteDefinition<TPath> : NormalizeRouteDefinition<TDefinition>;
425
422
  type OnlyIfNoParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends false ? Yes : No;
426
423
  type OnlyIfHasParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends true ? Yes : No;
427
424
  type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearchInput> = _ParamsInput<TDefinition> & {
@@ -429,8 +426,6 @@ type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearch
429
426
  '#'?: string | number;
430
427
  };
431
428
  type GetPathInputByRoute<TRoute extends AnyRoute | CallableRoute | string> = TRoute extends AnyRoute<any, infer TSearchInput> ? GetPathInput<Definition<TRoute>, TSearchInput> : TRoute extends string ? GetPathInput<TRoute, UnknownSearchInput> : never;
432
- type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>}`;
433
- type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? TPath : TDefinition extends `${infer TPath}*` ? TPath : TDefinition;
434
429
  type IsAny<T> = 0 extends 1 & T ? true : false;
435
430
  type _IsSameParams<T1 extends object | undefined, T2 extends object | undefined> = T1 extends undefined ? T2 extends undefined ? true : false : T2 extends undefined ? false : T1 extends T2 ? T2 extends T1 ? true : false : false;
436
431
  type _IsAncestor<T extends string, TAncestor extends string> = T extends TAncestor ? false : T extends `${TAncestor}${string}` ? true : false;
@@ -450,4 +445,4 @@ type SchemaRoute0<TInput extends Record<string, unknown>, TOutput extends Record
450
445
  safeParse: (input: unknown) => _SafeParseInputResult<TOutput>;
451
446
  };
452
447
 
453
- export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type ExactLocation, type ExactLocationState, type Extended, type ExtractRoute, type ExtractRoutesKeys, type GetPathInput, type GetPathInputByRoute, type HasParams, type HasRequiredParams, type HasWildcard, type IsAncestor, type IsAny, type IsDescendant, type IsParamsOptional, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type ReplacePathParams, Route0, type RouteConfigInput, type RouteToken, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type UnknownLocation, type UnknownLocationState, type UnknownSearchInput, type UnknownSearchParsed, type UnknownSearchParsedValue, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };
448
+ export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type EnsureLeadingSlash, type ExactLocation, type ExactLocationState, type Extended, type ExtractRoute, type ExtractRoutesKeys, type GetPathInput, type GetPathInputByRoute, type HasParams, type HasRequiredParams, type HasWildcard, type IsAncestor, type IsAny, type IsDescendant, type IsParamsOptional, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type NormalizeRouteDefinition, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type ReplacePathParams, Route0, type RouteConfigInput, type RouteToken, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type TrimTrailingSlash, type UnknownLocation, type UnknownLocationState, type UnknownSearchInput, type UnknownSearchParsed, type UnknownSearchParsedValue, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };
@@ -28,11 +28,8 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
28
28
  readonly params: _ParamsDefinition<TDefinition>;
29
29
  private _origin;
30
30
  private _callable;
31
- private _regexBaseStrictString?;
32
31
  private _regexBaseString?;
33
- private _regexStrictString?;
34
32
  private _regexString?;
35
- private _regexStrict?;
36
33
  private _regex?;
37
34
  private _regexAncestor?;
38
35
  private _captureKeys?;
@@ -54,13 +51,13 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
54
51
  *
55
52
  * If an existing route/callable route is provided, it is cloned.
56
53
  */
57
- static create<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>, config?: RouteConfigInput): CallableRoute<TDefinition>;
54
+ static create<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>, config?: RouteConfigInput): CallableRoute<NormalizeRouteDefinition<TDefinition>>;
58
55
  /**
59
56
  * Normalizes a definition/route into a callable route.
60
57
  *
61
58
  * Unlike `create`, passing a callable route returns the same instance.
62
59
  */
63
- static from<TDefinition extends string, TSearchInput extends UnknownSearchInput>(definition: TDefinition | AnyRoute<TDefinition, TSearchInput> | CallableRoute<TDefinition, TSearchInput>): CallableRoute<TDefinition, TSearchInput>;
60
+ static from<TDefinition extends string, TSearchInput extends UnknownSearchInput>(definition: TDefinition | AnyRoute<TDefinition, TSearchInput> | CallableRoute<TDefinition, TSearchInput>): CallableRoute<NormalizeRouteDefinition<TDefinition>, TSearchInput>;
64
61
  private static _getAbsPath;
65
62
  private static _getParamsDefinitionByDefinition;
66
63
  search<TNewSearchInput extends UnknownSearchInput>(): CallableRoute<TDefinition, TNewSearchInput>;
@@ -73,22 +70,17 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
73
70
  getTokens(): RouteToken[];
74
71
  /** Clones route with optional config override. */
75
72
  clone(config?: RouteConfigInput): CallableRoute<TDefinition>;
76
- get regexBaseStrictString(): string;
77
73
  get regexBaseString(): string;
78
- get regexStrictString(): string;
79
74
  get regexString(): string;
80
- get regexStrict(): RegExp;
81
75
  get regex(): RegExp;
82
76
  get regexAncestor(): RegExp;
83
77
  private get captureKeys();
84
78
  private get normalizedDefinition();
85
79
  private get definitionParts();
86
- /** Fast pathname check without building a full location object. */
80
+ /** Fast pathname exact match check without building a full location object. */
87
81
  isExactPathnameMatch(pathname: string): boolean;
88
- /** Creates a grouped strict regex pattern string from many routes. */
89
- static getRegexStrictStringGroup(routes: AnyRoute[]): string;
90
- /** Creates a strict grouped regex from many routes. */
91
- static getRegexStrictGroup(routes: AnyRoute[]): RegExp;
82
+ /** Fast pathname exact or ancestor match check without building a full location object. */
83
+ isExactOrAncestorPathnameMatch(pathname: string): boolean;
92
84
  /** Creates a grouped regex pattern string from many routes. */
93
85
  static getRegexStringGroup(routes: AnyRoute[]): string;
94
86
  /** Creates a grouped regex from many routes. */
@@ -420,8 +412,13 @@ type _RequiredParamKeys<TDefinition extends string> = {
420
412
  }[keyof _ParamsDefinition<TDefinition>];
421
413
  type ReplacePathParams<S extends string> = S extends `${infer Head}:${infer Tail}` ? Tail extends `${infer _Param}/${infer Rest}` ? ReplacePathParams<`${Head}${string}/${Rest}`> : `${Head}${string}` : S;
422
414
  type DedupeSlashes<S extends string> = S extends `${infer A}//${infer B}` ? DedupeSlashes<`${A}/${B}`> : S;
415
+ type EnsureLeadingSlash<S extends string> = S extends '' ? '/' : S extends `/${string}` ? S : `/${S}`;
416
+ type TrimTrailingSlash<S extends string> = S extends '/' ? '/' : S extends `${infer V}/` ? TrimTrailingSlash<V> : S;
417
+ type NormalizeRouteDefinition<S extends string> = TrimTrailingSlash<EnsureLeadingSlash<DedupeSlashes<S>>>;
423
418
  type EmptyRecord = Record<never, never>;
424
- type JoinPath<Parent extends string, Suffix extends string> = DedupeSlashes<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? A extends '' ? B extends '' ? '' : B extends `/${string}` ? B : `/${B}` : B extends '' ? A : A extends `${string}/` ? `${A}${B}` : B extends `/${string}` ? `${A}${B}` : `${A}/${B}` : never : never>;
419
+ type JoinPath<Parent extends string, Suffix extends string> = NormalizeRouteDefinition<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? NormalizeRouteDefinition<A> extends infer ANormalized extends string ? NormalizeRouteDefinition<B> extends infer BNormalized extends string ? BNormalized extends '/' ? ANormalized : ANormalized extends '/' ? BNormalized : `${ANormalized}/${BNormalized}` : never : never : never : never>;
420
+ type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${NormalizeRouteDefinition<JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>>}`;
421
+ type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? NormalizeRouteDefinition<TPath> : TDefinition extends `${infer TPath}*` ? NormalizeRouteDefinition<TPath> : NormalizeRouteDefinition<TDefinition>;
425
422
  type OnlyIfNoParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends false ? Yes : No;
426
423
  type OnlyIfHasParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends true ? Yes : No;
427
424
  type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearchInput> = _ParamsInput<TDefinition> & {
@@ -429,8 +426,6 @@ type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearch
429
426
  '#'?: string | number;
430
427
  };
431
428
  type GetPathInputByRoute<TRoute extends AnyRoute | CallableRoute | string> = TRoute extends AnyRoute<any, infer TSearchInput> ? GetPathInput<Definition<TRoute>, TSearchInput> : TRoute extends string ? GetPathInput<TRoute, UnknownSearchInput> : never;
432
- type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>}`;
433
- type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? TPath : TDefinition extends `${infer TPath}*` ? TPath : TDefinition;
434
429
  type IsAny<T> = 0 extends 1 & T ? true : false;
435
430
  type _IsSameParams<T1 extends object | undefined, T2 extends object | undefined> = T1 extends undefined ? T2 extends undefined ? true : false : T2 extends undefined ? false : T1 extends T2 ? T2 extends T1 ? true : false : false;
436
431
  type _IsAncestor<T extends string, TAncestor extends string> = T extends TAncestor ? false : T extends `${TAncestor}${string}` ? true : false;
@@ -450,4 +445,4 @@ type SchemaRoute0<TInput extends Record<string, unknown>, TOutput extends Record
450
445
  safeParse: (input: unknown) => _SafeParseInputResult<TOutput>;
451
446
  };
452
447
 
453
- export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type ExactLocation, type ExactLocationState, type Extended, type ExtractRoute, type ExtractRoutesKeys, type GetPathInput, type GetPathInputByRoute, type HasParams, type HasRequiredParams, type HasWildcard, type IsAncestor, type IsAny, type IsDescendant, type IsParamsOptional, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type ReplacePathParams, Route0, type RouteConfigInput, type RouteToken, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type UnknownLocation, type UnknownLocationState, type UnknownSearchInput, type UnknownSearchParsed, type UnknownSearchParsedValue, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };
448
+ export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type EnsureLeadingSlash, type ExactLocation, type ExactLocationState, type Extended, type ExtractRoute, type ExtractRoutesKeys, type GetPathInput, type GetPathInputByRoute, type HasParams, type HasRequiredParams, type HasWildcard, type IsAncestor, type IsAny, type IsDescendant, type IsParamsOptional, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type NormalizeRouteDefinition, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type ReplacePathParams, Route0, type RouteConfigInput, type RouteToken, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type TrimTrailingSlash, type UnknownLocation, type UnknownLocationState, type UnknownSearchInput, type UnknownSearchParsed, type UnknownSearchParsedValue, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };
package/dist/esm/index.js CHANGED
@@ -21,7 +21,7 @@ const getRouteTokens = (definition) => {
21
21
  return { kind: "static", value: segment };
22
22
  });
23
23
  };
24
- const getRouteRegexBaseStrictString = (definition) => {
24
+ const getRouteRegexBaseString = (definition) => {
25
25
  const tokens = getRouteTokens(definition);
26
26
  if (tokens.length === 0) return "";
27
27
  let pattern = "";
@@ -71,11 +71,14 @@ const validateRouteDefinition = (definition) => {
71
71
  }
72
72
  };
73
73
  const stripTrailingWildcard = (definition) => definition.replace(/\*\??$/, "");
74
+ const normalizeRouteDefinition = (definition) => {
75
+ const value = definition.replace(/\/{2,}/g, "/");
76
+ if (value === "" || value === "/") return "/";
77
+ const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
78
+ return withLeadingSlash.length > 1 && withLeadingSlash.endsWith("/") ? withLeadingSlash.slice(0, -1) : withLeadingSlash;
79
+ };
74
80
  const normalizePathname = (pathname) => {
75
- if (pathname.length > 1 && pathname.endsWith("/")) {
76
- return pathname.slice(0, -1);
77
- }
78
- return pathname;
81
+ return normalizeRouteDefinition(pathname);
79
82
  };
80
83
  const getNormalizedPathnameFromInput = (hrefOrHrefRelOrLocation) => {
81
84
  if (hrefOrHrefRelOrLocation instanceof URL) {
@@ -97,11 +100,8 @@ class Route0 {
97
100
  params;
98
101
  _origin;
99
102
  _callable;
100
- _regexBaseStrictString;
101
103
  _regexBaseString;
102
- _regexStrictString;
103
104
  _regexString;
104
- _regexStrict;
105
105
  _regex;
106
106
  _regexAncestor;
107
107
  _captureKeys;
@@ -121,9 +121,10 @@ class Route0 {
121
121
  this._origin = origin;
122
122
  }
123
123
  constructor(definition, config = {}) {
124
- validateRouteDefinition(definition);
125
- this.definition = definition;
126
- this.params = Route0._getParamsDefinitionByDefinition(definition);
124
+ const normalizedDefinition = normalizeRouteDefinition(definition);
125
+ validateRouteDefinition(normalizedDefinition);
126
+ this.definition = normalizedDefinition;
127
+ this.params = Route0._getParamsDefinitionByDefinition(normalizedDefinition);
127
128
  const { origin } = config;
128
129
  if (origin && typeof origin === "string" && origin.length) {
129
130
  this._origin = origin;
@@ -151,7 +152,10 @@ class Route0 {
151
152
  if (typeof definition === "function" || typeof definition === "object") {
152
153
  return definition.clone(config);
153
154
  }
154
- const original = new Route0(definition, config);
155
+ const original = new Route0(
156
+ normalizeRouteDefinition(definition),
157
+ config
158
+ );
155
159
  return original._callable;
156
160
  }
157
161
  /**
@@ -163,7 +167,9 @@ class Route0 {
163
167
  if (typeof definition === "function") {
164
168
  return definition;
165
169
  }
166
- const original = typeof definition === "object" ? definition : new Route0(definition);
170
+ const original = typeof definition === "object" ? definition : new Route0(
171
+ normalizeRouteDefinition(definition)
172
+ );
167
173
  return original._callable;
168
174
  }
169
175
  static _getAbsPath(origin, url) {
@@ -178,10 +184,12 @@ class Route0 {
178
184
  /** Extends the current route definition by appending a suffix route. */
179
185
  extend(suffixDefinition) {
180
186
  const sourceDefinitionWithoutWildcard = stripTrailingWildcard(this.definition);
181
- const definition = `${sourceDefinitionWithoutWildcard}/${suffixDefinition}`.replace(/\/{2,}/g, "/");
187
+ const definition = normalizeRouteDefinition(`${sourceDefinitionWithoutWildcard}/${suffixDefinition}`);
182
188
  return Route0.create(
183
189
  definition,
184
- { origin: this._origin }
190
+ {
191
+ origin: this._origin
192
+ }
185
193
  );
186
194
  }
187
195
  // implementation
@@ -271,36 +279,18 @@ class Route0 {
271
279
  clone(config) {
272
280
  return Route0.create(this.definition, config);
273
281
  }
274
- get regexBaseStrictString() {
275
- if (this._regexBaseStrictString === void 0) {
276
- this._regexBaseStrictString = getRouteRegexBaseStrictString(this.definition);
277
- }
278
- return this._regexBaseStrictString;
279
- }
280
282
  get regexBaseString() {
281
283
  if (this._regexBaseString === void 0) {
282
- this._regexBaseString = this.regexBaseStrictString.replace(/\/+$/, "") + "/?";
284
+ this._regexBaseString = getRouteRegexBaseString(this.definition).replace(/\/+$/, "") + "/?";
283
285
  }
284
286
  return this._regexBaseString;
285
287
  }
286
- get regexStrictString() {
287
- if (this._regexStrictString === void 0) {
288
- this._regexStrictString = `^${this.regexBaseStrictString}$`;
289
- }
290
- return this._regexStrictString;
291
- }
292
288
  get regexString() {
293
289
  if (this._regexString === void 0) {
294
290
  this._regexString = `^${this.regexBaseString}$`;
295
291
  }
296
292
  return this._regexString;
297
293
  }
298
- get regexStrict() {
299
- if (this._regexStrict === void 0) {
300
- this._regexStrict = new RegExp(this.regexStrictString);
301
- }
302
- return this._regexStrict;
303
- }
304
294
  get regex() {
305
295
  if (this._regex === void 0) {
306
296
  this._regex = new RegExp(this.regexString);
@@ -331,19 +321,14 @@ class Route0 {
331
321
  }
332
322
  return this._definitionParts;
333
323
  }
334
- /** Fast pathname check without building a full location object. */
324
+ /** Fast pathname exact match check without building a full location object. */
335
325
  isExactPathnameMatch(pathname) {
336
326
  return this.regex.test(normalizePathname(pathname));
337
327
  }
338
- /** Creates a grouped strict regex pattern string from many routes. */
339
- static getRegexStrictStringGroup(routes) {
340
- const patterns = routes.map((route) => route.regexStrictString).join("|");
341
- return `(${patterns})`;
342
- }
343
- /** Creates a strict grouped regex from many routes. */
344
- static getRegexStrictGroup(routes) {
345
- const patterns = Route0.getRegexStrictStringGroup(routes);
346
- return new RegExp(`^(${patterns})$`);
328
+ /** Fast pathname exact or ancestor match check without building a full location object. */
329
+ isExactOrAncestorPathnameMatch(pathname) {
330
+ const normalizedPathname = normalizePathname(pathname);
331
+ return this.regex.test(normalizedPathname) || this.regexAncestor.test(normalizedPathname);
347
332
  }
348
333
  /** Creates a grouped regex pattern string from many routes. */
349
334
  static getRegexStringGroup(routes) {
@@ -392,10 +377,7 @@ class Route0 {
392
377
  const base = abs ? void 0 : "http://example.com";
393
378
  const url = new URL(hrefOrHrefRelOrLocation, base);
394
379
  const search = parseSearchQuery(url.search);
395
- let pathname = url.pathname;
396
- if (pathname.length > 1 && pathname.endsWith("/")) {
397
- pathname = pathname.slice(0, -1);
398
- }
380
+ const pathname = normalizePathname(url.pathname);
399
381
  const hrefRel = pathname + url.search + url.hash;
400
382
  const location = {
401
383
  pathname,