export function setCookie(name: string, value: string, expires: number) {
    const d = new Date();
    d.setTime(d.getTime() + expires);
    const expires_at = "expires="+ d.toUTCString();
    document.cookie = name + "=" + value + ";" + expires_at + ";path=/";
}

export function getCookie(name: string): string {
    const name_with_equals = name + "=";
    const decodedCookie = decodeURIComponent(document.cookie);
    const ca = decodedCookie.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_with_equals) == 0) {
            return c.substring(name_with_equals.length, c.length);
        }
    }
    return "";
}