21 lines
595 B
TypeScript
21 lines
595 B
TypeScript
export function setCookie(cname: string, cvalue: string, exdate: string) {
|
|
const expires = exdate ? `;expires=${exdate}` : "";
|
|
document.cookie = `${cname}=${cvalue}${expires};path=/;`;
|
|
}
|
|
|
|
export function getCookie(cname: string) {
|
|
const name = cname + "=";
|
|
const dc = decodeURIComponent(document.cookie);
|
|
const ca = dc.split(";");
|
|
for (let i = 0; i < ca.length; i++) {
|
|
let c = ca[i];
|
|
while (c.charAt(0) == " ") {
|
|
c = c.substring(1);
|
|
}
|
|
if (c.indexOf(name) == 0) {
|
|
return c.substring(name.length, c.length);
|
|
}
|
|
}
|
|
return "";
|
|
}
|