Skip to content

Instantly share code, notes, and snippets.

@tonysaffo
Created November 2, 2018 12:16
Show Gist options
  • Save tonysaffo/42433bbbeb6461c08af5599e6f65b206 to your computer and use it in GitHub Desktop.
Save tonysaffo/42433bbbeb6461c08af5599e6f65b206 to your computer and use it in GitHub Desktop.
function getCookie(name) {
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
if (!matches) {
throw new Error('Cookie {0} not defined'.format(name));
}
return decodeURIComponent(matches[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment