Skip to content

Instantly share code, notes, and snippets.

@queckezz
Created October 5, 2013 15:35
Show Gist options
  • Save queckezz/6842365 to your computer and use it in GitHub Desktop.
Save queckezz/6842365 to your computer and use it in GitHub Desktop.
parse 'str=value' like document.cookie to objects
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