mirror of
https://github.com/itdoginfo/podkop.git
synced 2026-05-14 08:52:46 +03:00
23 lines
537 B
TypeScript
23 lines
537 B
TypeScript
export function parseQueryString(query: string): Record<string, string> {
|
|
const clean = query.startsWith('?') ? query.slice(1) : query;
|
|
|
|
return clean
|
|
.split('&')
|
|
.filter(Boolean)
|
|
.reduce(
|
|
(acc, pair) => {
|
|
const [rawKey, rawValue = ''] = pair.split('=');
|
|
|
|
if (!rawKey) {
|
|
return acc;
|
|
}
|
|
|
|
const key = decodeURIComponent(rawKey);
|
|
const value = decodeURIComponent(rawValue);
|
|
|
|
return { ...acc, [key]: value };
|
|
},
|
|
{} as Record<string, string>,
|
|
);
|
|
}
|