LocalStorage.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*! lowdb v1.0.0 */
  2. var LocalStorage =
  3. /******/ (function(modules) { // webpackBootstrap
  4. /******/ // The module cache
  5. /******/ var installedModules = {};
  6. /******/
  7. /******/ // The require function
  8. /******/ function __webpack_require__(moduleId) {
  9. /******/
  10. /******/ // Check if module is in cache
  11. /******/ if(installedModules[moduleId]) {
  12. /******/ return installedModules[moduleId].exports;
  13. /******/ }
  14. /******/ // Create a new module (and put it into the cache)
  15. /******/ var module = installedModules[moduleId] = {
  16. /******/ i: moduleId,
  17. /******/ l: false,
  18. /******/ exports: {}
  19. /******/ };
  20. /******/
  21. /******/ // Execute the module function
  22. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  23. /******/
  24. /******/ // Flag the module as loaded
  25. /******/ module.l = true;
  26. /******/
  27. /******/ // Return the exports of the module
  28. /******/ return module.exports;
  29. /******/ }
  30. /******/
  31. /******/
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/
  35. /******/ // expose the module cache
  36. /******/ __webpack_require__.c = installedModules;
  37. /******/
  38. /******/ // define getter function for harmony exports
  39. /******/ __webpack_require__.d = function(exports, name, getter) {
  40. /******/ if(!__webpack_require__.o(exports, name)) {
  41. /******/ Object.defineProperty(exports, name, {
  42. /******/ configurable: false,
  43. /******/ enumerable: true,
  44. /******/ get: getter
  45. /******/ });
  46. /******/ }
  47. /******/ };
  48. /******/
  49. /******/ // getDefaultExport function for compatibility with non-harmony modules
  50. /******/ __webpack_require__.n = function(module) {
  51. /******/ var getter = module && module.__esModule ?
  52. /******/ function getDefault() { return module['default']; } :
  53. /******/ function getModuleExports() { return module; };
  54. /******/ __webpack_require__.d(getter, 'a', getter);
  55. /******/ return getter;
  56. /******/ };
  57. /******/
  58. /******/ // Object.prototype.hasOwnProperty.call
  59. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  60. /******/
  61. /******/ // __webpack_public_path__
  62. /******/ __webpack_require__.p = "";
  63. /******/
  64. /******/ // Load entry module and return exports
  65. /******/ return __webpack_require__(__webpack_require__.s = 3);
  66. /******/ })
  67. /************************************************************************/
  68. /******/ ([
  69. /* 0 */,
  70. /* 1 */,
  71. /* 2 */,
  72. /* 3 */
  73. /***/ (function(module, exports, __webpack_require__) {
  74. "use strict";
  75. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  76. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  77. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  78. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  79. /* global localStorage */
  80. var Base = __webpack_require__(4);
  81. var LocalStorage = function (_Base) {
  82. _inherits(LocalStorage, _Base);
  83. function LocalStorage() {
  84. _classCallCheck(this, LocalStorage);
  85. return _possibleConstructorReturn(this, (LocalStorage.__proto__ || Object.getPrototypeOf(LocalStorage)).apply(this, arguments));
  86. }
  87. _createClass(LocalStorage, [{
  88. key: 'read',
  89. value: function read() {
  90. var data = localStorage.getItem(this.source);
  91. if (data) {
  92. return this.deserialize(data);
  93. } else {
  94. localStorage.setItem(this.source, this.serialize(this.defaultValue));
  95. return this.defaultValue;
  96. }
  97. }
  98. }, {
  99. key: 'write',
  100. value: function write(data) {
  101. localStorage.setItem(this.source, this.serialize(data));
  102. }
  103. }]);
  104. return LocalStorage;
  105. }(Base);
  106. module.exports = LocalStorage;
  107. /***/ }),
  108. /* 4 */
  109. /***/ (function(module, exports, __webpack_require__) {
  110. "use strict";
  111. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  112. var stringify = __webpack_require__(5);
  113. var Base = function Base(source) {
  114. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  115. _ref$defaultValue = _ref.defaultValue,
  116. defaultValue = _ref$defaultValue === undefined ? {} : _ref$defaultValue,
  117. _ref$serialize = _ref.serialize,
  118. serialize = _ref$serialize === undefined ? stringify : _ref$serialize,
  119. _ref$deserialize = _ref.deserialize,
  120. deserialize = _ref$deserialize === undefined ? JSON.parse : _ref$deserialize;
  121. _classCallCheck(this, Base);
  122. this.source = source;
  123. this.defaultValue = defaultValue;
  124. this.serialize = serialize;
  125. this.deserialize = deserialize;
  126. };
  127. module.exports = Base;
  128. /***/ }),
  129. /* 5 */
  130. /***/ (function(module, exports, __webpack_require__) {
  131. "use strict";
  132. // Pretty stringify
  133. module.exports = function stringify(obj) {
  134. return JSON.stringify(obj, null, 2);
  135. };
  136. /***/ })
  137. /******/ ]);