Skip to content

Instantly share code, notes, and snippets.

@simonsmith
Last active June 7, 2021 11:08
Show Gist options
  • Save simonsmith/5152680 to your computer and use it in GitHub Desktop.
Save simonsmith/5152680 to your computer and use it in GitHub Desktop.
function deparam(str) {
var o = {};
var reg = /\\?([^?=&]+)(=([^&#]*))?/g;
str.replace(reg, function($0, $1, $2, $3) {
if (typeof $3 == 'string') {
o[decodeURIComponent($1)] = decodeURIComponent($3);
}
});
return o;
}
// Use
deparam('name=simon')
// Returns
{
name: 'simon'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment