Last active
June 8, 2021 15:04
-
-
Save themgoncalves/17d53481a82346a051bd7b020c9c9f6f to your computer and use it in GitHub Desktop.
Parsing URL Query String into Object
This file contains 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
/** | |
* 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