Skip to content

Instantly share code, notes, and snippets.

@compulim
Last active March 11, 2020 23:56
Show Gist options
  • Save compulim/2e625e3e22f98b4f7cc0c29e302c3622 to your computer and use it in GitHub Desktop.
Save compulim/2e625e3e22f98b4f7cc0c29e302c3622 to your computer and use it in GitHub Desktop.
parseURLSearchParams
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