Skip to content

Instantly share code, notes, and snippets.

@pounard
Created December 29, 2016 14:46
Show Gist options
  • Save pounard/3338eae8951958318fc42e1c9a551c88 to your computer and use it in GitHub Desktop.
Save pounard/3338eae8951958318fc42e1c9a551c88 to your computer and use it in GitHub Desktop.
Parse those fucking query strings
function parseLink(uri) {
if (uri === "") {
return {};
}
var pos = uri.indexOf('?');
if (-1 !== pos) {
uri = uri.substr(pos + 1);
}
var ret = {};
uri.split("&").forEach(function (raw) {
var pos = raw.indexOf("=");
if (-1 !== pos) {
var key = raw.substr(0, pos);
var value = raw.substr(pos + 1);
ret[key] = decodeURIComponent(value.replace(/\+/g, " "));
}
});
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment