Skip to content

Instantly share code, notes, and snippets.

@themgoncalves
Last active June 8, 2021 15:04
Show Gist options
  • Save themgoncalves/17d53481a82346a051bd7b020c9c9f6f to your computer and use it in GitHub Desktop.
Save themgoncalves/17d53481a82346a051bd7b020c9c9f6f to your computer and use it in GitHub Desktop.
Parsing URL Query String into Object
/**
* Parse Query String
* @param {string} search
* @returns {Object.<string, string>}
*/
const parseQueryString = (search) =>
(search || '')
.replace(/^\?/g, '')
.split('&')
.reduce((acc, query) => {
const [key, value] = query.split('=');
if (key) {
acc[key] = decodeURIComponent(value);
}
return acc;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment