cozy/src/utils/get-params.ts
2023-05-11 16:50:17 +02:00

14 lines
361 B
TypeScript

export function getParams(url: URL): { [key: string]: string } | undefined {
if (url.search === "") return;
return Object.fromEntries(
url.search
.replace("?", "")
.split("&")
.map((paramstr) => paramstr.split("="))
.map(([key, value]) => [
key,
decodeURIComponent(value?.replace(/\+/g, "%20")),
])
);
}