Created
January 21, 2025 19:58
-
-
Save joemaffei/599cba0ce00316b143bd7c9f5c426301 to your computer and use it in GitHub Desktop.
Convert searchParams to object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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