All files / src/helpers cookies.ts

76.92% Statements 10/13
100% Branches 2/2
66.67% Functions 2/3
76.92% Lines 10/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 235x                     5x 4x 4x 4x 4x 4x 4x 2x   4x    
export const setCookie = (
  cookieName: string,
  cookieValue: string,
  minutesToExpire: number
) => {
  let date = new Date();
  date.setTime(date.getTime() + minutesToExpire * 60 * 1000);
  document.cookie =
    cookieName + '=' + cookieValue + '; expires=' + date.toUTCString();
};
 
export const getCookie = (cookieName: string) => {
  const name = cookieName + '=';
  const allCookieArray = document.cookie.split(';');
  let value: string | null = null;
  allCookieArray.forEach((item: string) => {
    const temp = item.trim();
    if (temp.indexOf(name) === 0)
      value = temp.substring(name.length, temp.length);
  });
  return value;
};