{"size": 1058, "ext": "js", "max_stars_repo_path": "src/Storage/localstorage.js", "max_stars_repo_name": "gplopes/mobx-keeper", "max_stars_repo_stars_event_min_datetime": "2018-01-06T13:49:22.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-27T14:30:39.000Z", "max_issues_repo_path": "src/Storage/localstorage.js", "max_issues_repo_name": "gplopes/mobx-keeper", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Storage/localstorage.js", "max_forks_repo_name": "gplopes/mobx-keeper", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.5106382979, "max_line_length": 78, "alphanum_fraction": 0.690926276}
/* global window */
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */

function start(storageName) {
  const storageState = window.localStorage.getItem(storageName);

  if (!storageState) {
    window.localStorage.setItem(storageName, JSON.stringify({}));
    return {};
  }
  return JSON.parse(storageState);
}

function end(storageName) {
  window.localStorage.setItem(storageName, JSON.stringify({}));
}

function get(storageName, itemKey) {
  try {
    const storageState = JSON.parse(window.localStorage.getItem(storageName));

    if (storageState) {
      return storageState[itemKey];
    }
  } catch (e) {
    console.error(`[keeper]: ${e}`);
    return false;
  }

  return null;
}

function set(storageName, item) {
  const getStorageState = window.localStorage.getItem(storageName);
  const storageState = JSON.parse(getStorageState);
  const newStorageState = Object.assign({}, storageState, item);

  window.localStorage.setItem(storageName, JSON.stringify(newStorageState));
}

export default {
  start,
  end,
  get,
  set,
};
