export const JS_ONE_DAY = 24 * 60 * 60 * 1000;
export function setCookie(name, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + days * JS_ONE_DAY);
expires = "; expires=" + date.toUTCString();
}
document.cookie = escape(name) + '=' + escape(value || "") + expires + '; path=/';
}
export function getCookie(name) {
let nameEQ = name + "=";
let cookies = document.cookie.split(';');
for (let cookie of cookies) {
while (cookie.charAt(0) === ' ') cookie = cookie.substring(1, cookie.length);
if (cookie.indexOf(nameEQ) == 0) return cookie.substring(nameEQ.length, cookie.length);
}
return null;
}
export function deleteCookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}