Attempt to clarify installation instructions a little
[vchess.git] / client / src / utils / cookie.js
CommitLineData
c66a829b 1// Source: https://www.quirksmode.org/js/cookies.html
6808d7a1 2export function setCookie(name, value) {
910d631b 3 const date = new Date();
6808d7a1 4 date.setTime(date.getTime() + 183 * 24 * 60 * 60 * 1000); //6 months
910d631b 5 const expires = "; expires=" + date.toGMTString();
a5200af9 6 document.cookie = name + "=" + value + expires + "; path=/;";
c66a829b
BA
7}
8
9export function getCookie(name, defaut) {
910d631b
BA
10 const nameEQ = name + "=";
11 const ca = document.cookie.split(";");
a5200af9
BA
12 for (let i = 0; i < ca.length; i++) {
13 let c = ca[i];
6808d7a1
BA
14 while (c.charAt(0) == " ") c = c.substring(1, c.length);
15 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
c66a829b
BA
16 }
17 return defaut; //cookie not found
18}
a5200af9
BA
19
20export function delCookie(name) {
21 document.cookie = name + "=; Max-Age=-1;";
22}