Skip to content

Instantly share code, notes, and snippets.

@joemaffei
Created January 21, 2025 19:58
Show Gist options
  • Save joemaffei/599cba0ce00316b143bd7c9f5c426301 to your computer and use it in GitHub Desktop.
Save joemaffei/599cba0ce00316b143bd7c9f5c426301 to your computer and use it in GitHub Desktop.
Convert searchParams to object
function searchParamsToObject(params: URLSearchParams) {
const uniqueKeys = [...new Set(params.keys())];
return Object.fromEntries(uniqueKeys.map(key => [
key,
params.getAll(key).length > 1 ? params.getAll(key) : params.get(key),
]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment