@devp0nt/route0 1.0.0-next.76 → 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.
- package/dist/cjs/index.cjs +24 -44
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +9 -16
- package/dist/esm/index.d.ts +9 -16
- package/dist/esm/index.js +24 -44
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -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
|
|
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,11 +70,8 @@ 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();
|
|
@@ -87,10 +81,6 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
|
|
|
87
81
|
isExactPathnameMatch(pathname: string): boolean;
|
|
88
82
|
/** Fast pathname exact or ancestor match check without building a full location object. */
|
|
89
83
|
isExactOrAncestorPathnameMatch(pathname: string): boolean;
|
|
90
|
-
/** Creates a grouped strict regex pattern string from many routes. */
|
|
91
|
-
static getRegexStrictStringGroup(routes: AnyRoute[]): string;
|
|
92
|
-
/** Creates a strict grouped regex from many routes. */
|
|
93
|
-
static getRegexStrictGroup(routes: AnyRoute[]): RegExp;
|
|
94
84
|
/** Creates a grouped regex pattern string from many routes. */
|
|
95
85
|
static getRegexStringGroup(routes: AnyRoute[]): string;
|
|
96
86
|
/** Creates a grouped regex from many routes. */
|
|
@@ -422,8 +412,13 @@ type _RequiredParamKeys<TDefinition extends string> = {
|
|
|
422
412
|
}[keyof _ParamsDefinition<TDefinition>];
|
|
423
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;
|
|
424
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>>>;
|
|
425
418
|
type EmptyRecord = Record<never, never>;
|
|
426
|
-
type JoinPath<Parent extends string, Suffix extends string> =
|
|
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>;
|
|
427
422
|
type OnlyIfNoParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends false ? Yes : No;
|
|
428
423
|
type OnlyIfHasParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends true ? Yes : No;
|
|
429
424
|
type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearchInput> = _ParamsInput<TDefinition> & {
|
|
@@ -431,8 +426,6 @@ type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearch
|
|
|
431
426
|
'#'?: string | number;
|
|
432
427
|
};
|
|
433
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;
|
|
434
|
-
type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>}`;
|
|
435
|
-
type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? TPath : TDefinition extends `${infer TPath}*` ? TPath : TDefinition;
|
|
436
429
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
437
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;
|
|
438
431
|
type _IsAncestor<T extends string, TAncestor extends string> = T extends TAncestor ? false : T extends `${TAncestor}${string}` ? true : false;
|
|
@@ -452,4 +445,4 @@ type SchemaRoute0<TInput extends Record<string, unknown>, TOutput extends Record
|
|
|
452
445
|
safeParse: (input: unknown) => _SafeParseInputResult<TOutput>;
|
|
453
446
|
};
|
|
454
447
|
|
|
455
|
-
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.d.ts
CHANGED
|
@@ -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
|
|
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,11 +70,8 @@ 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();
|
|
@@ -87,10 +81,6 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
|
|
|
87
81
|
isExactPathnameMatch(pathname: string): boolean;
|
|
88
82
|
/** Fast pathname exact or ancestor match check without building a full location object. */
|
|
89
83
|
isExactOrAncestorPathnameMatch(pathname: string): boolean;
|
|
90
|
-
/** Creates a grouped strict regex pattern string from many routes. */
|
|
91
|
-
static getRegexStrictStringGroup(routes: AnyRoute[]): string;
|
|
92
|
-
/** Creates a strict grouped regex from many routes. */
|
|
93
|
-
static getRegexStrictGroup(routes: AnyRoute[]): RegExp;
|
|
94
84
|
/** Creates a grouped regex pattern string from many routes. */
|
|
95
85
|
static getRegexStringGroup(routes: AnyRoute[]): string;
|
|
96
86
|
/** Creates a grouped regex from many routes. */
|
|
@@ -422,8 +412,13 @@ type _RequiredParamKeys<TDefinition extends string> = {
|
|
|
422
412
|
}[keyof _ParamsDefinition<TDefinition>];
|
|
423
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;
|
|
424
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>>>;
|
|
425
418
|
type EmptyRecord = Record<never, never>;
|
|
426
|
-
type JoinPath<Parent extends string, Suffix extends string> =
|
|
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>;
|
|
427
422
|
type OnlyIfNoParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends false ? Yes : No;
|
|
428
423
|
type OnlyIfHasParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends true ? Yes : No;
|
|
429
424
|
type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearchInput> = _ParamsInput<TDefinition> & {
|
|
@@ -431,8 +426,6 @@ type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearch
|
|
|
431
426
|
'#'?: string | number;
|
|
432
427
|
};
|
|
433
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;
|
|
434
|
-
type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>}`;
|
|
435
|
-
type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? TPath : TDefinition extends `${infer TPath}*` ? TPath : TDefinition;
|
|
436
429
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
437
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;
|
|
438
431
|
type _IsAncestor<T extends string, TAncestor extends string> = T extends TAncestor ? false : T extends `${TAncestor}${string}` ? true : false;
|
|
@@ -452,4 +445,4 @@ type SchemaRoute0<TInput extends Record<string, unknown>, TOutput extends Record
|
|
|
452
445
|
safeParse: (input: unknown) => _SafeParseInputResult<TOutput>;
|
|
453
446
|
};
|
|
454
447
|
|
|
455
|
-
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
|
|
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
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
this.
|
|
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(
|
|
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(
|
|
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}
|
|
187
|
+
const definition = normalizeRouteDefinition(`${sourceDefinitionWithoutWildcard}/${suffixDefinition}`);
|
|
182
188
|
return Route0.create(
|
|
183
189
|
definition,
|
|
184
|
-
{
|
|
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.
|
|
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);
|
|
@@ -340,16 +330,6 @@ class Route0 {
|
|
|
340
330
|
const normalizedPathname = normalizePathname(pathname);
|
|
341
331
|
return this.regex.test(normalizedPathname) || this.regexAncestor.test(normalizedPathname);
|
|
342
332
|
}
|
|
343
|
-
/** Creates a grouped strict regex pattern string from many routes. */
|
|
344
|
-
static getRegexStrictStringGroup(routes) {
|
|
345
|
-
const patterns = routes.map((route) => route.regexStrictString).join("|");
|
|
346
|
-
return `(${patterns})`;
|
|
347
|
-
}
|
|
348
|
-
/** Creates a strict grouped regex from many routes. */
|
|
349
|
-
static getRegexStrictGroup(routes) {
|
|
350
|
-
const patterns = Route0.getRegexStrictStringGroup(routes);
|
|
351
|
-
return new RegExp(`^(${patterns})$`);
|
|
352
|
-
}
|
|
353
333
|
/** Creates a grouped regex pattern string from many routes. */
|
|
354
334
|
static getRegexStringGroup(routes) {
|
|
355
335
|
const patterns = routes.map((route) => route.regexString).join("|");
|