import DataParse from "./DataParse";
var LocalStorage = {
  setLocalStorage: function setLocalStorage(key, val) {
    window.localStorage.setItem(key.toString(), DataParse.stringify(val));
    return true;
  },
  getLocalStorage: function getLocalStorage(key) {
    if (!key || typeof key !== 'string') return null;
    return DataParse.parse(window.localStorage.getItem(key));
  },
  getLocalStorages: function getLocalStorages() {
    var storages = window.localStorage.valueOf();
    var localStorages = null;
    for (var i = 0; i < storages.length; i++) {
      if (!localStorages) localStorages = {};
      var key = storages.key(i);
      localStorages[key] = DataParse.parse(storages[key]);
    }
    return localStorages;
  },
  removeLocalStorage: function removeLocalStorage(key) {
    window.localStorage.removeItem(key);
    return true;
  },
  removeLocalStorages: function removeLocalStorages(filter) {
    if (typeof filter !== 'function') return false;
    var removeKeys = [];
    var storages = window.localStorage.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.localStorage.removeItem(removeKey);
    }
    return true;
  },
  clearLocalStorage: function clearLocalStorage() {
    window.localStorage.clear();
    return true;
  }
};
export default LocalStorage;