compare-path
Version:
An easy-to-use package to detect if two URLs match each other by comparing their abstract paths
17 lines • 716 B
TypeScript
/**
* Type-level extraction of route params from a shape string. It recursively goes through each
* segment:
*
* - If a segment is like ":param", then it adds { param: string }.
* - If a segment is exactly "**", then it adds { rest: string[] }.
*/
export type ExtractRouteParams<S extends string> = S extends `/${infer Segment}/${infer Rest}` ? (Segment extends `:${infer Param}` ? {
[K in Param]: string;
} : Segment extends '**' ? {
rest: string[];
} : {}) & ExtractRouteParams<`/${Rest}`> : S extends `/${infer Segment}` ? Segment extends `:${infer Param}` ? {
[K in Param]: string;
} : Segment extends '**' ? {
rest: string[];
} : {} : {};
//# sourceMappingURL=extract-route-params.d.ts.map