Last active
August 29, 2015 14:02
-
-
Save Exodia/27869a4715bc58aee4de to your computer and use it in GitHub Desktop.
parse query string to object
This file contains hidden or 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 parseQuery(querystring){ | |
querystring = querystring.split('&'); | |
var query = {}; | |
for (var i = querystring.length - 1; i > -1; i--) { | |
var kv = querystring[i].split('='); | |
var key = decodeURIComponent(kv[0]); | |
query[key] = decodeURIComponent(kv[1]); | |
} | |
return query; | |
} | |
function stringifyQuery(query) { | |
var ret = []; | |
for (var k in query) { | |
ret.push(encodeURIComponent(k) + '=' + encodeURIComponent(query[k])); | |
} | |
return ret.join('&'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment