Skip to content

Instantly share code, notes, and snippets.

@bhargavkonkathi
Forked from rendro/parsecookie.js
Created November 20, 2018 11:34
Show Gist options
  • Save bhargavkonkathi/bfc39b377152a435810f1bccbce9bad5 to your computer and use it in GitHub Desktop.
Save bhargavkonkathi/bfc39b377152a435810f1bccbce9bad5 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