UNPKG

6.06 kBJavaScriptView Raw
1/*! lowdb v1.0.0 */
2var 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
75"use strict";
76
77
78var _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; }; }();
79
80function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
81
82function _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; }
83
84function _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; }
85
86/* global localStorage */
87var Base = __webpack_require__(4);
88
89var LocalStorage = function (_Base) {
90 _inherits(LocalStorage, _Base);
91
92 function LocalStorage() {
93 _classCallCheck(this, LocalStorage);
94
95 return _possibleConstructorReturn(this, (LocalStorage.__proto__ || Object.getPrototypeOf(LocalStorage)).apply(this, arguments));
96 }
97
98 _createClass(LocalStorage, [{
99 key: 'read',
100 value: function read() {
101 var data = localStorage.getItem(this.source);
102 if (data) {
103 return this.deserialize(data);
104 } else {
105 localStorage.setItem(this.source, this.serialize(this.defaultValue));
106 return this.defaultValue;
107 }
108 }
109 }, {
110 key: 'write',
111 value: function write(data) {
112 localStorage.setItem(this.source, this.serialize(data));
113 }
114 }]);
115
116 return LocalStorage;
117}(Base);
118
119module.exports = LocalStorage;
120
121/***/ }),
122/* 4 */
123/***/ (function(module, exports, __webpack_require__) {
124
125"use strict";
126
127
128function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
129
130var stringify = __webpack_require__(5);
131
132var Base = function Base(source) {
133 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
134 _ref$defaultValue = _ref.defaultValue,
135 defaultValue = _ref$defaultValue === undefined ? {} : _ref$defaultValue,
136 _ref$serialize = _ref.serialize,
137 serialize = _ref$serialize === undefined ? stringify : _ref$serialize,
138 _ref$deserialize = _ref.deserialize,
139 deserialize = _ref$deserialize === undefined ? JSON.parse : _ref$deserialize;
140
141 _classCallCheck(this, Base);
142
143 this.source = source;
144 this.defaultValue = defaultValue;
145 this.serialize = serialize;
146 this.deserialize = deserialize;
147};
148
149module.exports = Base;
150
151/***/ }),
152/* 5 */
153/***/ (function(module, exports, __webpack_require__) {
154
155"use strict";
156
157
158// Pretty stringify
159module.exports = function stringify(obj) {
160 return JSON.stringify(obj, null, 2);
161};
162
163/***/ })
164/******/ ]);
\No newline at end of file