Created
October 5, 2013 15:35
-
-
Save queckezz/6842365 to your computer and use it in GitHub Desktop.
parse 'str=value' like document.cookie to objects
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
var decode = decodeURIComponent; | |
function parse(str) { | |
var obj = {}; | |
var pairs = str.split(/ *; */); | |
var pair; | |
if ('' == pairs[0]) return obj; | |
for (var i = 0; i < pairs.length; ++i) { | |
pair = pairs[i].split('='); | |
obj[decode(pair[0])] = decode(pair[1]); | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment