Project

General

Profile

« Previous | Next » 

Revision 51195

added utils.ts

View differences:

modules/uoa-repository-dashboard-gui/trunk/app/domain/utils.ts
1
/**
2
 * Created by stefanos on 2/3/2017.
3
 */
4

  
5
export function getCookie(name: string) : string {
6
    let ca: Array<string> = document.cookie.split(';');
7
    let caLen: number = ca.length;
8
    let cookieName = `${name}=`;
9
    let c: string;
10

  
11
    for (let i: number = 0; i < caLen; i += 1) {
12
        c = ca[i].replace(/^\s+/g, '');
13
        if (c.indexOf(cookieName) == 0) {
14
            return c.substring(cookieName.length, c.length);
15
        }
16
    }
17
    return null;
18
}
19

  
20
export function deleteCookie(name) {
21
    setCookie(name, '', -1);
22
}
23

  
24
function setCookie(name: string, value: string, expireDays: number, path: string = '') {
25
    let d:Date = new Date();
26
    d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
27
    let expires:string = `expires=${d.toUTCString()}`;
28
    let cpath:string = path ? `; path=${path}` : '';
29
    document.cookie = `${name}=${value}; ${expires}${cpath}`;
30
}

Also available in: Unified diff