Skip to content

Instantly share code, notes, and snippets.

@tongyifan
Forked from rendro/parsecookie.js
Created February 6, 2020 04:00
Show Gist options
  • Save tongyifan/e12762074165937d187956f4e6685855 to your computer and use it in GitHub Desktop.
Save tongyifan/e12762074165937d187956f4e6685855 to your computer and use it in GitHub Desktop.
Parse document.cookie into object
document.cookie.split(';').map(function(c) {
return c.trim().split('=').map(decodeURIComponent);
}).reduce(function(a, b) {
try {
a[b[0]] = JSON.parse(b[1]);
} catch (e) {
a[b[0]] = b[1];
}
return a;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment