Created
December 29, 2016 14:46
-
-
Save pounard/3338eae8951958318fc42e1c9a551c88 to your computer and use it in GitHub Desktop.
Parse those fucking query strings
This file contains 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 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