-
-
Save bga/503933 to your computer and use it in GitHub Desktop.
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
/* No regexp. indexOf only */ | |
window._queryToJSON = function(query) | |
{ | |
if(query == null || query.length < 2) | |
return {}; | |
var p = 0; | |
if(query.charAt(p) == '?') | |
++p; | |
if(query.charAt(p) == '&') | |
++p; | |
var ret = {}; | |
var _unescape = unescape; | |
if(query.charAt(query.length - 1) != '&') | |
query += '&'; | |
var queryLen = query.length - 1; | |
--p; | |
while(++p < queryLen) | |
{ | |
var key = _unescape(query.slice(p, (p = query.indexOf('=', p)))); | |
var value = _unescape(query.slice(++p, (p = query.indexOf('&', p)))); | |
ret[key] = value; | |
} | |
return ret; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment