StorageController.browser.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. /**
  3. * Copyright (c) 2015-present, Parse, LLC.
  4. * All rights reserved.
  5. *
  6. * This source code is licensed under the BSD-style license found in the
  7. * LICENSE file in the root directory of this source tree. An additional grant
  8. * of patent rights can be found in the PATENTS file in the same directory.
  9. *
  10. * @flow
  11. * @private
  12. */
  13. /* global localStorage */
  14. var StorageController = {
  15. async: 0,
  16. getItem: function (path
  17. /*: string*/
  18. )
  19. /*: ?string*/
  20. {
  21. return localStorage.getItem(path);
  22. },
  23. setItem: function (path
  24. /*: string*/
  25. , value
  26. /*: string*/
  27. ) {
  28. try {
  29. localStorage.setItem(path, value);
  30. } catch (e) {
  31. // Quota exceeded, possibly due to Safari Private Browsing mode
  32. // eslint-disable-next-line no-console
  33. console.log(e.message);
  34. }
  35. },
  36. removeItem: function (path
  37. /*: string*/
  38. ) {
  39. localStorage.removeItem(path);
  40. },
  41. getAllKeys: function () {
  42. var keys = [];
  43. for (var i = 0; i < localStorage.length; i += 1) {
  44. keys.push(localStorage.key(i));
  45. }
  46. return keys;
  47. },
  48. clear: function () {
  49. localStorage.clear();
  50. }
  51. };
  52. module.exports = StorageController;