mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
15 lines
518 B
TypeScript
15 lines
518 B
TypeScript
import { compile } from "path-to-regexp"
|
|
|
|
export interface IURLParams<P extends object = {}, Q extends object = {}> {
|
|
params?: P;
|
|
query?: Q;
|
|
}
|
|
|
|
export function buildURL<P extends object = {}, Q extends object = {}>(path: string | any) {
|
|
const pathBuilder = compile(String(path));
|
|
return function ({ params, query }: IURLParams<P, Q> = {}) {
|
|
const queryParams = query ? new URLSearchParams(Object.entries(query)).toString() : ""
|
|
return pathBuilder(params) + (queryParams ? `?${queryParams}` : "")
|
|
}
|
|
}
|