first commit
This commit is contained in:
24
node_modules/lowdb/adapters/Base.js
generated
vendored
Normal file
24
node_modules/lowdb/adapters/Base.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var stringify = require('./_stringify');
|
||||
|
||||
var Base = function Base(source) {
|
||||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
||||
_ref$defaultValue = _ref.defaultValue,
|
||||
defaultValue = _ref$defaultValue === undefined ? {} : _ref$defaultValue,
|
||||
_ref$serialize = _ref.serialize,
|
||||
serialize = _ref$serialize === undefined ? stringify : _ref$serialize,
|
||||
_ref$deserialize = _ref.deserialize,
|
||||
deserialize = _ref$deserialize === undefined ? JSON.parse : _ref$deserialize;
|
||||
|
||||
_classCallCheck(this, Base);
|
||||
|
||||
this.source = source;
|
||||
this.defaultValue = defaultValue;
|
||||
this.serialize = serialize;
|
||||
this.deserialize = deserialize;
|
||||
};
|
||||
|
||||
module.exports = Base;
|
65
node_modules/lowdb/adapters/FileAsync.js
generated
vendored
Normal file
65
node_modules/lowdb/adapters/FileAsync.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
|
||||
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; }; }();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
// Not using async/await on purpose to avoid adding regenerator-runtime
|
||||
// to lowdb dependencies
|
||||
var fs = require('graceful-fs');
|
||||
var pify = require('pify');
|
||||
var steno = require('steno');
|
||||
var Base = require('./Base');
|
||||
|
||||
var readFile = pify(fs.readFile);
|
||||
var writeFile = pify(steno.writeFile);
|
||||
|
||||
var FileAsync = function (_Base) {
|
||||
_inherits(FileAsync, _Base);
|
||||
|
||||
function FileAsync() {
|
||||
_classCallCheck(this, FileAsync);
|
||||
|
||||
return _possibleConstructorReturn(this, (FileAsync.__proto__ || Object.getPrototypeOf(FileAsync)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(FileAsync, [{
|
||||
key: 'read',
|
||||
value: function read() {
|
||||
var _this2 = this;
|
||||
|
||||
// fs.exists is deprecated but not fs.existsSync
|
||||
if (fs.existsSync(this.source)) {
|
||||
// Read database
|
||||
return readFile(this.source, 'utf-8').then(function (data) {
|
||||
// Handle blank file
|
||||
var trimmed = data.trim();
|
||||
return trimmed ? _this2.deserialize(trimmed) : _this2.defaultValue;
|
||||
}).catch(function (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
e.message = `Malformed JSON in file: ${_this2.source}\n${e.message}`;
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
} else {
|
||||
// Initialize
|
||||
return writeFile(this.source, this.serialize(this.defaultValue)).then(function () {
|
||||
return _this2.defaultValue;
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'write',
|
||||
value: function write(data) {
|
||||
return writeFile(this.source, this.serialize(data));
|
||||
}
|
||||
}]);
|
||||
|
||||
return FileAsync;
|
||||
}(Base);
|
||||
|
||||
module.exports = FileAsync;
|
60
node_modules/lowdb/adapters/FileSync.js
generated
vendored
Normal file
60
node_modules/lowdb/adapters/FileSync.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
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; }; }();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var Base = require('./Base');
|
||||
|
||||
var readFile = fs.readFileSync;
|
||||
var writeFile = fs.writeFileSync;
|
||||
|
||||
// Same code as in FileAsync, minus `await`
|
||||
|
||||
var FileSync = function (_Base) {
|
||||
_inherits(FileSync, _Base);
|
||||
|
||||
function FileSync() {
|
||||
_classCallCheck(this, FileSync);
|
||||
|
||||
return _possibleConstructorReturn(this, (FileSync.__proto__ || Object.getPrototypeOf(FileSync)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(FileSync, [{
|
||||
key: 'read',
|
||||
value: function read() {
|
||||
// fs.exists is deprecated but not fs.existsSync
|
||||
if (fs.existsSync(this.source)) {
|
||||
// Read database
|
||||
try {
|
||||
var data = readFile(this.source, 'utf-8').trim();
|
||||
// Handle blank file
|
||||
return data ? this.deserialize(data) : this.defaultValue;
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
e.message = `Malformed JSON in file: ${this.source}\n${e.message}`;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
// Initialize
|
||||
writeFile(this.source, this.serialize(this.defaultValue));
|
||||
return this.defaultValue;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'write',
|
||||
value: function write(data) {
|
||||
return writeFile(this.source, this.serialize(data));
|
||||
}
|
||||
}]);
|
||||
|
||||
return FileSync;
|
||||
}(Base);
|
||||
|
||||
module.exports = FileSync;
|
44
node_modules/lowdb/adapters/LocalStorage.js
generated
vendored
Normal file
44
node_modules/lowdb/adapters/LocalStorage.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
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; }; }();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
/* global localStorage */
|
||||
var Base = require('./Base');
|
||||
|
||||
var LocalStorage = function (_Base) {
|
||||
_inherits(LocalStorage, _Base);
|
||||
|
||||
function LocalStorage() {
|
||||
_classCallCheck(this, LocalStorage);
|
||||
|
||||
return _possibleConstructorReturn(this, (LocalStorage.__proto__ || Object.getPrototypeOf(LocalStorage)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(LocalStorage, [{
|
||||
key: 'read',
|
||||
value: function read() {
|
||||
var data = localStorage.getItem(this.source);
|
||||
if (data) {
|
||||
return this.deserialize(data);
|
||||
} else {
|
||||
localStorage.setItem(this.source, this.serialize(this.defaultValue));
|
||||
return this.defaultValue;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'write',
|
||||
value: function write(data) {
|
||||
localStorage.setItem(this.source, this.serialize(data));
|
||||
}
|
||||
}]);
|
||||
|
||||
return LocalStorage;
|
||||
}(Base);
|
||||
|
||||
module.exports = LocalStorage;
|
33
node_modules/lowdb/adapters/Memory.js
generated
vendored
Normal file
33
node_modules/lowdb/adapters/Memory.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
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; }; }();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
var Base = require('./Base');
|
||||
|
||||
module.exports = function (_Base) {
|
||||
_inherits(Memory, _Base);
|
||||
|
||||
function Memory() {
|
||||
_classCallCheck(this, Memory);
|
||||
|
||||
return _possibleConstructorReturn(this, (Memory.__proto__ || Object.getPrototypeOf(Memory)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Memory, [{
|
||||
key: 'read',
|
||||
value: function read() {
|
||||
return this.defaultValue;
|
||||
}
|
||||
}, {
|
||||
key: 'write',
|
||||
value: function write() {}
|
||||
}]);
|
||||
|
||||
return Memory;
|
||||
}(Base);
|
6
node_modules/lowdb/adapters/_stringify.js
generated
vendored
Normal file
6
node_modules/lowdb/adapters/_stringify.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
// Pretty stringify
|
||||
module.exports = function stringify(obj) {
|
||||
return JSON.stringify(obj, null, 2);
|
||||
};
|
Reference in New Issue
Block a user