/**
 * 设置 localStorage
 * @param {string} key
 * @param {*} value
 */
export function setItem(key, value) {
  let _val = typeof value === 'object' ? JSON.stringify(value) : value;
  localStorage.setItem(key, _val);
}

/**
 * 获取 localStorage
 * @param {string} key
 */
export function getItem(key) {
  try {
    return JSON.parse(localStorage.getItem(key));
  } catch (e) {
    return null;
  }
}

/**
 * 删除 localStorage
 * @param {string} key
 */
export function removeItem(key) {
  localStorage.removeItem(key);
}

/**
 * 清空 localStorage
 */
export function clear() {
  localStorage.clear();
}
