import DataParse from "./DataParse";
var SessionStorage = {
  setSessionStorage: function setSessionStorage(key, value) {
    window.sessionStorage.setItem(key.toString(), DataParse.stringify(value));
    return true;
  },
  getSessionStorage: function getSessionStorage(key) {
    if (!key || typeof key !== 'string') return null;
    return DataParse.parse(window.sessionStorage.getItem(key));
  },
  getSessionStorages: function getSessionStorages() {
    var storages = window.sessionStorage.valueOf();
    var sessionStorages = null;
    for (var i = 0; i < storages.length; i++) {
      if (!sessionStorages) sessionStorages = {};
      var key = storages.key(i);
      sessionStorages[key] = DataParse.parse(storages[key]);
    }
    return sessionStorages;
  },
  removeSessionStorage: function removeSessionStorage(key) {
    window.sessionStorage.removeItem(key);
    return true;
  },
  removeSessionStorages: function removeSessionStorages(filter) {
    if (typeof filter !== 'function') return false;
    var removeKeys = [];
    var storages = window.sessionStorage.valueOf();
    for (var i = 0; i < storages.length; i++) {
      var key = storages.key(i);
      if (filter(key)) {
        removeKeys.push(key);
      }
    }
    for (var _i = 0, _removeKeys = removeKeys; _i < _removeKeys.length; _i++) {
      var removeKey = _removeKeys[_i];
      window.sessionStorage.removeItem(removeKey);
    }
    return true;
  },
  clearSessionStorage: function clearSessionStorage() {
    window.sessionStorage.clear();
    return true;
  }
};
export default SessionStorage;