"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.LocalStorage = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var LocalStorage =
/*#__PURE__*/
function () {
  function LocalStorage(prefix) {
    if (prefix === void 0) {
      prefix = '';
    }

    (0, _defineProperty2.default)(this, "prefix", '');
    (0, _defineProperty2.default)(this, "cache", {});
    this.prefix = prefix ? prefix + '.' : '';
  }

  var _proto = LocalStorage.prototype;

  _proto.setItem = function setItem(key, value) {
    this.cache[key] = value;

    if (window.localStorage) {
      try {
        window.localStorage.setItem(this.prefix + key, JSON.stringify(value));
      } catch (error) {// Ignore
      }
    }
  };

  _proto.getItem = function getItem(key, defaultValue) {
    if (defaultValue === void 0) {
      defaultValue = undefined;
    }

    if (key in this.cache) {
      return this.cache[key];
    }

    if (window.localStorage) {
      try {
        var value = window.localStorage.getItem(this.prefix + key);

        if (value !== null) {
          value = JSON.parse(value);
          this.cache[key] = value;
          return value;
        }
      } catch (error) {// Ignore
      }

      return defaultValue;
    }
  };

  return LocalStorage;
}();

exports.LocalStorage = LocalStorage;