StorageController.browser.js 793 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. /**
  3. * @flow
  4. * @private
  5. */
  6. /* global localStorage */
  7. var StorageController = {
  8. async: 0,
  9. getItem: function (path /*: string*/) /*: ?string*/{
  10. return localStorage.getItem(path);
  11. },
  12. setItem: function (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: function (path /*: string*/) {
  21. localStorage.removeItem(path);
  22. },
  23. getAllKeys: function () {
  24. var keys = [];
  25. for (var i = 0; i < localStorage.length; i += 1) {
  26. keys.push(localStorage.key(i));
  27. }
  28. return keys;
  29. },
  30. clear: function () {
  31. localStorage.clear();
  32. }
  33. };
  34. module.exports = StorageController;