StorageController.browser.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. console.log(e.message);
  33. }
  34. },
  35. removeItem: function (path
  36. /*: string*/
  37. ) {
  38. localStorage.removeItem(path);
  39. },
  40. getAllKeys: function () {
  41. var keys = [];
  42. for (var i = 0; i < localStorage.length; i += 1) {
  43. keys.push(localStorage.key(i));
  44. }
  45. return keys;
  46. },
  47. clear: function () {
  48. localStorage.clear();
  49. }
  50. };
  51. module.exports = StorageController;