LocalStorage.js

// COMMON
export function readKey(key) {
  const value = localStorage.getItem(key);
  try {
    return JSON.parse(value);
  } catch {
    return value;
  }
}

export function writeKey(key, value) {
  value = typeof value === 'string' ? value : JSON.stringify(value);
  localStorage.setItem(key, value);
}

export function removeKey(key) {
  localStorage.removeItem(key);
}

// USER
export function readUser() {
  return readKey('user');
}

export function writeUser(user) {
  writeKey('user', user);
}

export function removeUser() {
  removeKey('user');
}