All files / site storage.ts

50% Statements 3/6
62.5% Branches 5/8
50% Functions 1/2
50% Lines 3/6

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    2x                               8x 8x      
import type {Generic} from '../types'
 
export const storage: {
  name: string
  perm: Storage
  copy: Generic
  set(opt: string, value: boolean | string | number): void
  get(opt?: string): string | number | boolean | Generic
} = {
  name: window.location.pathname || 'default',
  perm: window.localStorage,
  copy: {},
  set: function (opt: string, value: boolean | string | number) {
    const s: Generic = JSON.parse(this.perm.getItem(this.name) || '{}')
    s[opt] = value
    this.perm.setItem(this.name, JSON.stringify(s))
  },
  get: function (opt?: string) {
    const s: Generic = JSON.parse(this.perm.getItem(this.name) || '{}')
    return opt ? s[opt] : s
  },
}