Socket
Socket
Sign inDemoInstall

lowdb

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lowdb - npm Package Compare versions

Comparing version 0.17.1 to 0.17.2

75

adapters/FileAsync.js

@@ -5,4 +5,2 @@ 'use strict';

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -14,2 +12,4 @@

// Not using async/await on purpose to avoid adding regenerator-runtime
// to lowdb dependencies
var fs = require('graceful-fs');

@@ -34,56 +34,25 @@ var pify = require('pify');

key: 'read',
value: function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
var data;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!fs.existsSync(this.source)) {
_context.next = 14;
break;
}
value: function read() {
var _this2 = this;
_context.prev = 1;
_context.next = 4;
return readFile(this.source, 'utf-8');
case 4:
data = _context.sent.trim();
return _context.abrupt('return', data ? this.deserialize(data) : this.defaultValue);
case 8:
_context.prev = 8;
_context.t0 = _context['catch'](1);
if (_context.t0 instanceof SyntaxError) {
_context.t0.message = 'Malformed JSON in file: ' + this.source + '\n' + _context.t0.message;
}
throw _context.t0;
case 12:
_context.next = 17;
break;
case 14:
_context.next = 16;
return writeFile(this.source, this.serialize(this.defaultValue));
case 16:
return _context.abrupt('return', this.defaultValue);
case 17:
case 'end':
return _context.stop();
}
// 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}`;
}
}, _callee, this, [[1, 8]]);
}));
function read() {
return _ref.apply(this, arguments);
throw e;
});
} else {
// Initialize
return writeFile(this.source, this.serialize(this.defaultValue)).then(function () {
return _this2.defaultValue;
});
}
return read;
}()
}
}, {

@@ -90,0 +59,0 @@ key: 'write',

@@ -40,3 +40,3 @@ 'use strict';

if (e instanceof SyntaxError) {
e.message = 'Malformed JSON in file: ' + this.source + '\n' + e.message;
e.message = `Malformed JSON in file: ${this.source}\n${e.message}`;
}

@@ -43,0 +43,0 @@ throw e;

@@ -1,2 +0,2 @@

/*! lowdb v0.17.1 */
/*! lowdb v0.17.2 */
var LocalStorage =

@@ -3,0 +3,0 @@ /******/ (function(modules) { // webpackBootstrap

@@ -1,2 +0,2 @@

/*! lowdb v0.17.1 */
/*! lowdb v0.17.2 */
var LocalStorage=function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([,,,function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(4),s=function(e){function t(){return n(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return i(t,e),u(t,[{key:"read",value:function(){var e=localStorage.getItem(this.source);return e?this.deserialize(e):(localStorage.setItem(this.source,this.serialize(this.defaultValue)),this.defaultValue)}},{key:"write",value:function(e){localStorage.setItem(this.source,this.serialize(e))}}]),t}(a);e.exports=s},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=r(5),i=function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.defaultValue,u=void 0===i?{}:i,a=r.serialize,s=void 0===a?o:a,c=r.deserialize,l=void 0===c?JSON.parse:c;n(this,e),this.source=t,this.defaultValue=u,this.serialize=s,this.deserialize=l};e.exports=i},function(e,t,r){"use strict";e.exports=function(e){return JSON.stringify(e,null,2)}}]);

@@ -1,2 +0,2 @@

/*! lowdb v0.17.1 */
/*! lowdb v0.17.2 */
var low =

@@ -75,4 +75,2 @@ /******/ (function(modules) { // webpackBootstrap

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var lodash = __webpack_require__(1);

@@ -82,3 +80,3 @@ var isPromise = __webpack_require__(2);

module.exports = function (adapter) {
if ((typeof adapter === 'undefined' ? 'undefined' : _typeof(adapter)) !== 'object') {
if (typeof adapter !== 'object') {
throw new Error('An adapter must be provided, see https://github.com/typicode/lowdb/#usage');

@@ -85,0 +83,0 @@ }

@@ -1,2 +0,2 @@

/*! lowdb v0.17.1 */
var low=function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=n(1),u=n(2);t.exports=function(t){function e(t){return i.__wrapped__=t,i}if("object"!==(void 0===t?"undefined":r(t)))throw new Error("An adapter must be provided, see https://github.com/typicode/lowdb/#usage");var n=o.runInContext(),i=n.chain({});return n.prototype.write=n.wrap(n.prototype.value,function(t){var e=t.apply(this);return i.write(e)}),i._=n,i.read=function(){var n=t.read();return u(n)?n.then(e):e(n)},i.write=function(e){var n=t.write(i.getState());return u(n)?n.then(function(){return e}):e},i.getState=function(){return i.__wrapped__},i.setState=function(t){return e(t)},i.read()}},function(t,e){t.exports=_},function(t,e){function n(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}t.exports=n}]);
/*! lowdb v0.17.2 */
var low=function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";var n=r(1),o=r(2);t.exports=function(t){function e(t){return u.__wrapped__=t,u}if("object"!=typeof t)throw new Error("An adapter must be provided, see https://github.com/typicode/lowdb/#usage");var r=n.runInContext(),u=r.chain({});return r.prototype.write=r.wrap(r.prototype.value,function(t){var e=t.apply(this);return u.write(e)}),u._=r,u.read=function(){var r=t.read();return o(r)?r.then(e):e(r)},u.write=function(e){var r=t.write(u.getState());return o(r)?r.then(function(){return e}):e},u.getState=function(){return u.__wrapped__},u.setState=function(t){return e(t)},u.read()}},function(t,e){t.exports=_},function(t,e){function r(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}t.exports=r}]);

@@ -0,0 +0,0 @@ # lowdb/lib/fp

@@ -0,0 +0,0 @@ # Examples

@@ -40,3 +40,3 @@ 'use strict';

module.exports = {
init: init
init
};
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var lodash = require('lodash');

@@ -9,3 +7,3 @@ var isPromise = require('is-promise');

module.exports = function (adapter) {
if ((typeof adapter === 'undefined' ? 'undefined' : _typeof(adapter)) !== 'object') {
if (typeof adapter !== 'object') {
throw new Error('An adapter must be provided, see https://github.com/typicode/lowdb/#usage');

@@ -12,0 +10,0 @@ }

{
"name": "lowdb",
"version": "0.17.1",
"version": "0.17.2",
"description": "JSON database for Node and the browser powered by lodash API",

@@ -5,0 +5,0 @@ "keywords": [

@@ -183,2 +183,19 @@ # Lowdb

## Adapters API
Please note this only applies to adapters bundled with Lowdb. Third-party adapters may have different options.
For convenience, `FileSync`, `FileAsync` and `LocalBrowser` accept the following options:
* __defaultValue__ if file doesn't exist, this value will be used to set the initial state (default: `{}`)
* __serialize/deserialize__ functions used before writing and after reading (default: `JSON.stringify` and `JSON.parse`)
```js
const adapter = new FileSync('array.yaml', {
defaultValue: [],
serialize: (array) => toYamlString(array),
deserialize: (string) => fromYamlString(string)
})
```
## Guide

@@ -343,3 +360,3 @@

`FileSync` and `FileAsync` accept custom serializing and deserializing functions.
`FileSync`, `FileAsync` and `LocalStorage` accept custom `serialize` and `deserialize` functions. You can use them to add encryption logic.

@@ -359,3 +376,3 @@ ```js

lowdb is a convenient method for storing data without setting up a database server. It is fast enough and safe to be used as an embedded database.
Lowdb is a convenient method for storing data without setting up a database server. It is fast enough and safe to be used as an embedded database.

@@ -362,0 +379,0 @@ However, if you seek high performance and scalability more than simplicity, you should probably stick to traditional databases like MongoDB.

@@ -0,0 +0,0 @@ var path = require('path')

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc