Socket
Socket
Sign inDemoInstall

lowdb

Package Overview
Dependencies
1
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 3.0.0

2

lib/adapters/JSONFile.d.ts
import { Adapter } from '../Low.js';
export declare class JSONFile<T> implements Adapter<T> {
private adapter;
#private;
constructor(filename: string);

@@ -5,0 +5,0 @@ read(): Promise<T | null>;

@@ -0,8 +1,21 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _JSONFile_adapter;
import { TextFile } from './TextFile.js';
export class JSONFile {
constructor(filename) {
this.adapter = new TextFile(filename);
_JSONFile_adapter.set(this, void 0);
__classPrivateFieldSet(this, _JSONFile_adapter, new TextFile(filename), "f");
}
async read() {
const data = await this.adapter.read();
const data = await __classPrivateFieldGet(this, _JSONFile_adapter, "f").read();
if (data === null) {

@@ -16,4 +29,5 @@ return null;

write(obj) {
return this.adapter.write(JSON.stringify(obj, null, 2));
return __classPrivateFieldGet(this, _JSONFile_adapter, "f").write(JSON.stringify(obj, null, 2));
}
}
_JSONFile_adapter = new WeakMap();
import { SyncAdapter } from '../LowSync.js';
export declare class JSONFileSync<T> implements SyncAdapter<T> {
private adapter;
#private;
constructor(filename: string);

@@ -5,0 +5,0 @@ read(): T | null;

@@ -0,8 +1,21 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _JSONFileSync_adapter;
import { TextFileSync } from './TextFileSync.js';
export class JSONFileSync {
constructor(filename) {
this.adapter = new TextFileSync(filename);
_JSONFileSync_adapter.set(this, void 0);
__classPrivateFieldSet(this, _JSONFileSync_adapter, new TextFileSync(filename), "f");
}
read() {
const data = this.adapter.read();
const data = __classPrivateFieldGet(this, _JSONFileSync_adapter, "f").read();
if (data === null) {

@@ -16,4 +29,5 @@ return null;

write(obj) {
this.adapter.write(JSON.stringify(obj, null, 2));
__classPrivateFieldGet(this, _JSONFileSync_adapter, "f").write(JSON.stringify(obj, null, 2));
}
}
_JSONFileSync_adapter = new WeakMap();
import { SyncAdapter } from '../LowSync.js';
export declare class LocalStorage<T> implements SyncAdapter<T> {
private key;
#private;
constructor(key: string);

@@ -5,0 +5,0 @@ read(): T | null;

@@ -0,7 +1,20 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _LocalStorage_key;
export class LocalStorage {
constructor(key) {
this.key = key;
_LocalStorage_key.set(this, void 0);
__classPrivateFieldSet(this, _LocalStorage_key, key, "f");
}
read() {
const value = localStorage.getItem(this.key);
const value = localStorage.getItem(__classPrivateFieldGet(this, _LocalStorage_key, "f"));
if (value === null) {

@@ -13,4 +26,5 @@ return null;

write(obj) {
localStorage.setItem(this.key, JSON.stringify(obj));
localStorage.setItem(__classPrivateFieldGet(this, _LocalStorage_key, "f"), JSON.stringify(obj));
}
}
_LocalStorage_key = new WeakMap();
import { Adapter } from '../Low.js';
export declare class Memory<T> implements Adapter<T> {
private data;
#private;
read(): Promise<T | null>;
write(obj: T): Promise<void>;
}

@@ -0,12 +1,25 @@

var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _Memory_data;
export class Memory {
constructor() {
this.data = null;
_Memory_data.set(this, null);
}
read() {
return Promise.resolve(this.data);
return Promise.resolve(__classPrivateFieldGet(this, _Memory_data, "f"));
}
write(obj) {
this.data = obj;
__classPrivateFieldSet(this, _Memory_data, obj, "f");
return Promise.resolve();
}
}
_Memory_data = new WeakMap();
import { SyncAdapter } from '../LowSync.js';
export declare class MemorySync<T> implements SyncAdapter<T> {
private data;
#private;
read(): T | null;
write(obj: T): void;
}

@@ -0,11 +1,24 @@

var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _MemorySync_data;
export class MemorySync {
constructor() {
this.data = null;
_MemorySync_data.set(this, null);
}
read() {
return this.data || null;
return __classPrivateFieldGet(this, _MemorySync_data, "f") || null;
}
write(obj) {
this.data = obj;
__classPrivateFieldSet(this, _MemorySync_data, obj, "f");
}
}
_MemorySync_data = new WeakMap();
import { Adapter } from '../Low.js';
export declare class TextFile implements Adapter<string> {
private filename;
private writer;
#private;
constructor(filename: string);

@@ -6,0 +5,0 @@ read(): Promise<string | null>;

@@ -0,1 +1,13 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _TextFile_filename, _TextFile_writer;
import fs from 'fs';

@@ -5,4 +17,6 @@ import { Writer } from 'steno';

constructor(filename) {
this.filename = filename;
this.writer = new Writer(filename);
_TextFile_filename.set(this, void 0);
_TextFile_writer.set(this, void 0);
__classPrivateFieldSet(this, _TextFile_filename, filename, "f");
__classPrivateFieldSet(this, _TextFile_writer, new Writer(filename), "f");
}

@@ -12,3 +26,3 @@ async read() {

try {
data = await fs.promises.readFile(this.filename, 'utf-8');
data = await fs.promises.readFile(__classPrivateFieldGet(this, _TextFile_filename, "f"), 'utf-8');
}

@@ -24,4 +38,5 @@ catch (e) {

write(str) {
return this.writer.write(str);
return __classPrivateFieldGet(this, _TextFile_writer, "f").write(str);
}
}
_TextFile_filename = new WeakMap(), _TextFile_writer = new WeakMap();
import { SyncAdapter } from '../LowSync.js';
export declare class TextFileSync implements SyncAdapter<string> {
private tempFilename;
private filename;
#private;
constructor(filename: string);

@@ -6,0 +5,0 @@ read(): string | null;

@@ -0,1 +1,13 @@

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _TextFileSync_tempFilename, _TextFileSync_filename;
import fs from 'fs';

@@ -5,4 +17,6 @@ import path from 'path';

constructor(filename) {
this.filename = filename;
this.tempFilename = path.join(path.dirname(filename), `.${path.basename(filename)}.tmp`);
_TextFileSync_tempFilename.set(this, void 0);
_TextFileSync_filename.set(this, void 0);
__classPrivateFieldSet(this, _TextFileSync_filename, filename, "f");
__classPrivateFieldSet(this, _TextFileSync_tempFilename, path.join(path.dirname(filename), `.${path.basename(filename)}.tmp`), "f");
}

@@ -12,3 +26,3 @@ read() {

try {
data = fs.readFileSync(this.filename, 'utf-8');
data = fs.readFileSync(__classPrivateFieldGet(this, _TextFileSync_filename, "f"), 'utf-8');
}

@@ -24,5 +38,6 @@ catch (e) {

write(str) {
fs.writeFileSync(this.tempFilename, str);
fs.renameSync(this.tempFilename, this.filename);
fs.writeFileSync(__classPrivateFieldGet(this, _TextFileSync_tempFilename, "f"), str);
fs.renameSync(__classPrivateFieldGet(this, _TextFileSync_tempFilename, "f"), __classPrivateFieldGet(this, _TextFileSync_filename, "f"));
}
}
_TextFileSync_tempFilename = new WeakMap(), _TextFileSync_filename = new WeakMap();
import { MissingAdapterError } from './MissingAdapterError.js';
export class Low {
constructor(adapter) {
this.data = null;
Object.defineProperty(this, "adapter", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "data", {
enumerable: true,
configurable: true,
writable: true,
value: null
});
if (adapter) {

@@ -6,0 +17,0 @@ this.adapter = adapter;

import { MissingAdapterError } from './MissingAdapterError.js';
export class LowSync {
constructor(adapter) {
this.data = null;
Object.defineProperty(this, "adapter", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "data", {
enumerable: true,
configurable: true,
writable: true,
value: null
});
if (adapter) {

@@ -6,0 +17,0 @@ this.adapter = adapter;

{
"name": "lowdb",
"version": "2.1.0",
"version": "3.0.0",
"description": "Tiny local JSON database for Node, Electron and the browser",
"keywords": [
"database",
"db",
"electron",
"embed",
"embedded",
"flat",
"JSON",
"local",
"localStorage",
"browser",
"esm"
],
"homepage": "https://github.com/typicode/lowdb#readme",
"bugs": {
"url": "https://github.com/typicode/lowdb/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/typicode/lowdb.git"
},
"funding": "https://github.com/sponsors/typicode",
"license": "MIT",
"author": "Typicode <typicode@gmail.com>",
"type": "module",
"exports": "./lib/index.js",
"types": "lib",
"files": [
"lib",
"!lib/**/*.test.*",
"LICENSE-MIT",

@@ -14,3 +40,3 @@ "LICENSE-PARITY",

"scripts": {
"test": "ava",
"test": "npm run build && xv lib",
"lint": "eslint src --ext .ts --ignore-path .gitignore",

@@ -22,56 +48,23 @@ "build": "del-cli lib && tsc",

},
"repository": {
"type": "git",
"url": "git+https://github.com/typicode/lowdb.git"
"dependencies": {
"steno": "^2.1.0"
},
"keywords": [
"database",
"electron",
"embed",
"embedded",
"flat",
"JSON",
"local",
"localStorage"
],
"author": "Typicode <typicode@gmail.com>",
"license": "Parity-7.0.0 AND MIT WITH Patron-1.0.0",
"bugs": {
"url": "https://github.com/typicode/lowdb/issues"
},
"homepage": "https://github.com/typicode/lowdb#readme",
"devDependencies": {
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@commitlint/prompt-cli": "^12.0.1",
"@tsconfig/node12": "^1.0.7",
"@types/lodash": "^4.14.168",
"@types/node": "^15.0.3",
"@typicode/eslint-config": "^0.1.0",
"ava": "^3.15.0",
"del-cli": "^3.0.1",
"husky": "^6.0.0",
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@commitlint/prompt-cli": "^13.1.0",
"@sindresorhus/tsconfig": "^2.0.0",
"@types/lodash": "^4.14.172",
"@types/node": "^16.9.1",
"@typicode/eslint-config": "^0.1.2",
"del-cli": "^4.0.1",
"husky": "^7.0.2",
"lodash": "^4.17.21",
"tempy": "^1.0.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
"tempy": "^2.0.0",
"typescript": "^4.4.3",
"xv": "^1.0.2"
},
"dependencies": {
"steno": "^1.0.0"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"types": "lib",
"ava": {
"extensions": {
"ts": "module"
},
"nonSemVerExperiments": {
"configurableModuleFormat": true
},
"nodeArguments": [
"--loader=ts-node/esm"
]
}
}

@@ -6,3 +6,6 @@ # lowdb [![](http://img.shields.io/npm/dm/lowdb.svg?style=flat)](https://www.npmjs.org/package/lowdb) [![Node.js CI](https://github.com/typicode/lowdb/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/lowdb/actions/workflows/node.js.yml)

```js
// This is pure JS, not specific to lowdb ;)
db.data.posts.push({ id: 1, title: 'lowdb is awesome' })
// Save to file
db.write()

@@ -20,18 +23,22 @@ ```

## Free for Open Source
If you like lowdb, see also [xv](https://github.com/typicode/xv) (test runner) and [steno](https://github.com/typicode/steno) (fast file writer).
To help with OSS funding, lowdb v2 is released under Parity license for a limited time. It'll be released under MIT license once the __goal of 100 [sponsors](https://github.com/sponsors/typicode)__ is reached (currently at 57) or in five months.
## Sponsors
Meanwhile, lowdb v2 can be freely used in Open Source projects. Sponsors can use it in any type of project.
<br>
<br>
If you've installed this new version without knowing about the license change, you're excused for 30 days. There's also a 30 days trial. See license files for more details.
<p align="center">
<a href="https://mockend.com/" target="_blank">
<img src="https://jsonplaceholder.typicode.com/mockend.svg" height="70px">
</a>
</p>
Thank you for your support!
<br>
<br>
__Note:__ if you're already sponsoring [husky](https://github.com/typicode/husky), you can use lowdb v2 today :)
[Become a sponsor and have your company logo here](https://github.com/sponsors/typicode).
## Companies
Please help me build OSS 👉 [GitHub Sponsors](https://github.com/sponsors/typicode)
[Become a sponsor and have your company logo here](https://github.com/sponsors/typicode).
## Features

@@ -56,6 +63,11 @@

_Lowdb 2 is a pure ESM package. If you're having trouble importing it in your project, please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)._
```js
import { join } from 'path'
import { join, dirname } from 'path'
import { Low, JSONFile } from 'lowdb'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url));
// Use JSON file for storage

@@ -72,2 +84,3 @@ const file = join(__dirname, 'db.json')

db.data ||= { posts: [] }
// db.data = db.data || { posts: [] } // for node < v15.x

@@ -114,3 +127,3 @@ // Create and query items using plain JS

```js
import lodash from lodash
import lodash from 'lodash'

@@ -125,3 +138,3 @@ // ...

.find({ id: 1 })
.value()
.value() // Important: value() needs to be called to execute chain
```

@@ -163,3 +176,3 @@

Calls `adaper.read()` and sets `db.data`.
Calls `adapter.read()` and sets `db.data`.

@@ -289,9 +302,7 @@ **Note:** `JSONFile` and `JSONFileSync` adapters will set `db.data` to `null` if file doesn't exist.

```js
import { Adapter, Low, TextFile } from 'Low.js'
import { Adapter, Low, TextFile } from 'lowdb'
import YAML from 'yaml'
export class YAMLFile {
private adapter
constructor(filename: string) {
class YAMLFile {
constructor(filename) {
this.adapter = new TextFile(filename)

@@ -327,5 +338,1 @@ }

If you plan to scale, it's highly recommended to use databases like PostgreSQL, MongoDB, ...
## License
[License Zero Parity 7.0.0](https://paritylicense.com/versions/7.0.0.html) and MIT (contributions) with exception [License Zero Patron 1.0.0](https://patronlicense.com/versions/1.0.0).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc