All files / src/browser cache.ts

10% Statements 2/20
0% Branches 0/16
0% Functions 0/8
10% Lines 2/20

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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                1x                                                 1x                                              
interface YSANDYL {
  set: (key: string, value: string) => void;
  get: (key: string) => string | null;
  remove: (key: string) => void;
  clear: () => void;
}
 
// sessionStorage
export const YS: YSANDYL = {
  set: (name: string, value: string): void => {
    if (typeof window !== 'undefined') {
      window.sessionStorage.setItem(name, value)
    }
  },
  get: (name: string): string | null => {
    if (typeof window !== 'undefined') {
      return window.sessionStorage.getItem(name)
    }
    return null
  },
  remove: (name: string): void => {
    if (typeof window !== 'undefined') {
      window.sessionStorage.removeItem(name)
    }
  },
  clear: (): void => {
    if (typeof window !== 'undefined') {
      window.sessionStorage.clear();
    }
  }
}
 
// locationStorage
export const YL: YSANDYL = {
  set: (name: string, value: string): void => {
    if (typeof window !== 'undefined') {
      window.localStorage.setItem(name, value)
    }
  },
  get: (name: string): string | null => {
    if (typeof window !== 'undefined') {
      return window.localStorage.getItem(name)
    }
    return null
  },
  remove: (name: string): void => {
    if (typeof window !== 'undefined') {
      window.localStorage.removeItem(name)
    }
  },
  clear: (): void => {
    if (typeof window !== 'undefined') {
      window.localStorage.clear();
    }
  }
}