Last active
March 11, 2020 23:56
-
-
Save compulim/2e625e3e22f98b4f7cc0c29e302c3622 to your computer and use it in GitHub Desktop.
parseURLSearchParams
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 parseURLSearchParams(search) { | |
return search | |
.replace(/^\?/, '') | |
.split('&') | |
.reduce((params, keyValue) => { | |
const [key, value] = keyValue.split('='); | |
const decodedKey = decodeURIComponent(key); | |
if (key && key !== '__proto__' && key !== 'constructor' && key !== 'prototype') { | |
params[decodedKey] = decodeURIComponent(value); | |
} | |
return params; | |
}, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment