SIGN IN SIGN UP
2019-03-08 15:13:45 +03:00
function getCookie(name) {
2019-03-09 10:33:47 +03:00
let matches = document.cookie.match(new RegExp(
2019-03-08 15:13:45 +03:00
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
2019-03-09 10:33:47 +03:00
function setCookie(name, value, options = {}) {
2019-03-08 15:13:45 +03:00
2019-03-09 10:33:47 +03:00
options = {
path: '/',
// add other defaults here if necessary
...options
};
2019-03-08 15:13:45 +03:00
2020-01-19 22:32:38 +01:00
if (options.expires instanceof Date) {
2019-03-09 10:33:47 +03:00
options.expires = options.expires.toUTCString();
2019-03-08 15:13:45 +03:00
}
2019-03-09 10:33:47 +03:00
let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
2019-03-08 15:13:45 +03:00
2019-03-09 10:33:47 +03:00
for (let optionKey in options) {
updatedCookie += "; " + optionKey;
let optionValue = options[optionKey];
if (optionValue !== true) {
updatedCookie += "=" + optionValue;
2019-03-08 15:13:45 +03:00
}
}
document.cookie = updatedCookie;
}
2019-03-09 10:33:47 +03:00
2019-03-08 15:13:45 +03:00
function deleteCookie(name) {
setCookie(name, "", {
2019-03-09 10:33:47 +03:00
'max-age': -1
2019-03-08 15:13:45 +03:00
})
2019-03-09 10:33:47 +03:00
}