StorageController.browser.js 742 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. /**
  3. * @flow
  4. * @private
  5. */
  6. /* global localStorage */
  7. const StorageController = {
  8. async: 0,
  9. getItem(path /*: string*/) /*: ?string*/{
  10. return localStorage.getItem(path);
  11. },
  12. setItem(path /*: string*/, value /*: string*/) {
  13. try {
  14. localStorage.setItem(path, value);
  15. } catch (e) {
  16. // Quota exceeded, possibly due to Safari Private Browsing mode
  17. console.log(e.message);
  18. }
  19. },
  20. removeItem(path /*: string*/) {
  21. localStorage.removeItem(path);
  22. },
  23. getAllKeys() {
  24. const keys = [];
  25. for (let i = 0; i < localStorage.length; i += 1) {
  26. keys.push(localStorage.key(i));
  27. }
  28. return keys;
  29. },
  30. clear() {
  31. localStorage.clear();
  32. }
  33. };
  34. module.exports = StorageController;