UNPKG

@bearstudio/lunalink

Version:

Lightweight TypeScript library to efficiently maintain and build URLs

26 lines (24 loc) 1.12 kB
type ExplicitAny = any; /** Type to extract params from a path */ type ExtractParams<Path extends string> = Path extends `${string}:${infer Param}?` ? { [K in Param]: string; } : Path extends `${string}:${infer Param}.${infer Rest}` ? { [K in Param]: string; } & ExtractParams<`${Rest}`> : Path extends `${string}:${infer Param}/${infer Rest}` ? { [K in Param]: string; } & ExtractParams<`/${Rest}`> : Path extends `${string}:${infer Param}` ? { [K in Param]: string; } : {}; /** Type to add more params */ type ParamsDefaultType = Record<string, ExplicitAny>; declare function lunalink<Path extends string>(path: Path, params: ExtractParams<Path> & ParamsDefaultType, config?: { baseURL?: string | URL; }): string; /** * @param path1 first path to join (can be the start or the end) * @param path2 second path to join (can be the start or the end) * @param separator The separaotor to use (default to `/`) * @returns The joined paths using the provided separator */ declare function join(path1: string, path2: string, separator?: string): string; export { type ExtractParams, join, lunalink };