StorageController.browser.js 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. */
  12. /* global localStorage */
  13. var StorageController = {
  14. async: 0,
  15. getItem: function (path
  16. /*: string*/
  17. )
  18. /*: ?string*/
  19. {
  20. return localStorage.getItem(path);
  21. },
  22. setItem: function (path
  23. /*: string*/
  24. , value
  25. /*: string*/
  26. ) {
  27. try {
  28. localStorage.setItem(path, value);
  29. } catch (e) {// Quota exceeded, possibly due to Safari Private Browsing mode
  30. }
  31. },
  32. removeItem: function (path
  33. /*: string*/
  34. ) {
  35. localStorage.removeItem(path);
  36. },
  37. clear: function () {
  38. localStorage.clear();
  39. }
  40. };
  41. module.exports = StorageController;