export function writeCookie(name: string, value: string, path?: string, duration?: number): void {
    let cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);

    if (path) {
        cookie += '; path=' + path;
    }

    if (duration) {
        let date = new Date();
        date.setTime(date.getTime() + duration * 24 * 60 * 60 * 1000);
        cookie += '; expires=' + date.toUTCString();
    }

    document.cookie = cookie;
}

export function readCookie(name): string | null {
    let value = document.cookie.match(new RegExp('(?:^|;)\\s*' + name + '=([^;]*)'));
    return value ? decodeURIComponent(value[1]) : null;
}
