Skip to content

Instantly share code, notes, and snippets.

@KOBA789
Created July 22, 2015 17:04
Show Gist options
  • Save KOBA789/d0a9ac807ea751bfb8fc to your computer and use it in GitHub Desktop.
Save KOBA789/d0a9ac807ea751bfb8fc to your computer and use it in GitHub Desktop.
QueryString Parser/Stringifier
// THIS CODE IS LICENCED UNDER WTFPL
var qs = {
get: function () {
return qs.parse(window.location.search.substring(1));
},
parse: function (str) {
return str.split('&').map(function (value) { return value.split('='); })
.reduce(function (obj, pair) {
obj[pair[0]] = decodeURIComponent(pair[1]);
return obj;
}, {});
},
stringify: function (obj) {
return Object.keys(obj).map(function (key) {
return [key, encodeURIComponent(obj[key])].join('=');
}).join('&');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment