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 5.1.0 to 6.0.0

lib/adapters/browser/LocalStorage.d.ts

7

lib/adapters/Memory.d.ts

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

import { Adapter } from '../Low.js';
import { Adapter, SyncAdapter } from '../core/Low.js';
export declare class Memory<T> implements Adapter<T> {

@@ -7,1 +7,6 @@ #private;

}
export declare class MemorySync<T> implements SyncAdapter<T> {
#private;
read(): T | null;
write(obj: T): void;
}

@@ -12,3 +12,3 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {

};
var _Memory_data;
var _Memory_data, _MemorySync_data;
export class Memory {

@@ -27,1 +27,13 @@ constructor() {

_Memory_data = new WeakMap();
export class MemorySync {
constructor() {
_MemorySync_data.set(this, null);
}
read() {
return __classPrivateFieldGet(this, _MemorySync_data, "f") || null;
}
write(obj) {
__classPrivateFieldSet(this, _MemorySync_data, obj, "f");
}
}
_MemorySync_data = new WeakMap();

4

lib/browser.d.ts

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

export * from './adapters/LocalStorage.js';
export * from './adapters/SessionStorage.js';
export * from './adapters/browser/LocalStorage.js';
export * from './adapters/browser/SessionStorage.js';

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

export * from './adapters/LocalStorage.js';
export * from './adapters/SessionStorage.js';
export * from './adapters/browser/LocalStorage.js';
export * from './adapters/browser/SessionStorage.js';
export * from './adapters/Memory.js';
export * from './adapters/MemorySync.js';
export * from './Low.js';
export * from './LowSync.js';
export * from './core/Low.js';
export * from './adapters/Memory.js';
export * from './adapters/MemorySync.js';
export * from './Low.js';
export * from './LowSync.js';
export * from './core/Low.js';

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

export * from './adapters/JSONFile.js';
export * from './adapters/JSONFileSync.js';
export * from './adapters/TextFile.js';
export * from './adapters/TextFileSync.js';
export * from './adapters/node/JSONFile.js';
export * from './adapters/node/TextFile.js';

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

export * from './adapters/JSONFile.js';
export * from './adapters/JSONFileSync.js';
export * from './adapters/TextFile.js';
export * from './adapters/TextFileSync.js';
export * from './adapters/node/JSONFile.js';
export * from './adapters/node/TextFile.js';
{
"name": "lowdb",
"version": "5.1.0",
"version": "6.0.0",
"description": "Tiny local JSON database for Node, Electron and the browser",

@@ -39,2 +39,3 @@ "keywords": [

"lib",
"!lib/examples/**/*",
"!lib/**/*.test.*"

@@ -54,11 +55,13 @@ ],

"devDependencies": {
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@commitlint/prompt-cli": "^17.4.2",
"@commitlint/cli": "^17.6.1",
"@commitlint/config-conventional": "^17.6.1",
"@commitlint/prompt-cli": "^17.6.1",
"@sindresorhus/tsconfig": "^3.0.1",
"@types/lodash": "^4.14.191",
"@types/node": "^18.11.18",
"@types/express": "^4.17.17",
"@types/lodash": "^4.14.194",
"@types/node": "^18.15.11",
"@typicode/eslint-config": "^1.1.0",
"del-cli": "^5.0.0",
"eslint": "^8.33.0",
"eslint": "^8.38.0",
"express-async-handler": "^1.2.0",
"husky": "^8.0.3",

@@ -68,8 +71,8 @@ "lodash": "^4.17.21",

"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"typescript": "^5.0.4",
"xv": "^2.1.1"
},
"engines": {
"node": ">=14.16"
"node": ">=16"
}
}

@@ -6,6 +6,4 @@ # 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
// Edit db.json content using native JS API
db.data
.posts
.push({ id: 1, title: 'lowdb is awesome' })
// Edit db.json content using plain JavaScript
db.data.posts.push({ id: 1, title: 'lowdb is awesome' })

@@ -25,3 +23,3 @@ // Save to file

If you like lowdb, see also [xv](https://github.com/typicode/xv) (test runner) and [steno](https://github.com/typicode/steno) (fast file writer).
If you like lowdb, please [sponsor](https://github.com/sponsors/typicode).

@@ -42,13 +40,11 @@ ## Sponsors

[Become a sponsor and have your company logo here](https://github.com/sponsors/typicode).
[Become a sponsor and have your company logo here](https://github.com/sponsors/typicode) 👉 [GitHub Sponsors](https://github.com/sponsors/typicode)
Please help me build OSS 👉 [GitHub Sponsors](https://github.com/sponsors/typicode)
## Features
- __Lightweight__
- __Minimalist__
- __TypeScript__
- __plain JS__
- Atomic write
- **Lightweight**
- **Minimalist**
- **TypeScript**
- **plain JavaScript**
- Safe atomic writes
- Hackable:

@@ -68,3 +64,3 @@ - Change storage, file format (JSON, YAML, ...) or add encryption via [adapters](#adapters)

__Next.js__: there's a [known issue](https://github.com/typicode/lowdb/issues/554). Until it's fixed, please use this [workaround](https://github.com/typicode/lowdb/issues/554#issuecomment-1345252506) or lowdb `^4.0.0`.
**Next.js**: there's a [known issue](https://github.com/typicode/lowdb/issues/554). Until it's fixed, please use this [workaround](https://github.com/typicode/lowdb/issues/554#issuecomment-1345252506) or lowdb `^4.0.0`.

@@ -79,23 +75,20 @@ ```js

// File path
const __dirname = dirname(fileURLToPath(import.meta.url));
// db.json file path
const __dirname = dirname(fileURLToPath(import.meta.url))
const file = join(__dirname, 'db.json')
// Configure lowdb to write to JSONFile
// Configure lowdb to write data to JSON file
const adapter = new JSONFile(file)
const db = new Low(adapter)
const defaultData = { posts: [] }
const db = new Low(adapter, defaultData)
// Read data from JSON file, this will set db.data content
// If JSON file doesn't exist, defaultData is used instead
await db.read()
// If db.json doesn't exist, db.data will be null
// Use the code below to set default data
// db.data = db.data || { posts: [] } // For Node < v15.x
db.data ||= { posts: [] } // For Node >= 15.x
// Create and query items using native JS API
// Create and query items using plain JavaScript
db.data.posts.push('hello world')
const firstPost = db.data.posts[0]
// Alternatively, you can also use this syntax if you prefer
// If you don't want to type db.data everytime, you can use destructuring assignment
const { posts } = db.data

@@ -121,15 +114,11 @@ posts.push('hello world')

type Data = {
words: string[]
messages: string[]
}
const defaultData: Data = { messages: [] }
const adapter = new JSONFile<Data>('db.json')
const db = new Low(adapter)
const db = new Low<Data>(adapter)
db.data
.words
.push('foo') // ✅ Success
db.data
.words
.push(1) // ❌ TypeScript error
db.data.messages.push('foo') // ✅ Success
db.data.messages.push(1) // ❌ TypeScript error
```

@@ -145,4 +134,4 @@

type Post = {
id: number;
title: string;
id: number
title: string
}

@@ -159,2 +148,5 @@

const defaultData: Data = {
posts: [],
}
const adapter = new JSONFile<Data>('db.json')

@@ -165,11 +157,8 @@ const db = new LowWithLodash(adapter)

// Instead of db.data use db.chain to access lodash API
const post = db.chain
.get('posts')
.find({ id: 1 })
.value() // Important: value() must be called to execute chain
const post = db.chain.get('posts').find({ id: 1 }).value() // Important: value() must be called to execute chain
```
### CLI, Server and Browser usage
### CLI, Server, Browser and in tests usage
See [`examples/`](/examples) directory.
See [`src/examples/`](src/examples) directory.

@@ -188,3 +177,3 @@ ## API

const db = new Low(new JSONFile('file.json'))
const db = new Low(new JSONFile('file.json'), {})
await db.read()

@@ -200,3 +189,3 @@ await db.write()

const db = new LowSync(new JSONFileSync('file.json'))
const db = new LowSync(new JSONFileSync('file.json'), {})
db.read()

@@ -256,4 +245,4 @@ db.write()

new Low(new JSONFile(filename))
new LowSync(new JSONFileSync(filename))
new Low(new JSONFile(filename), {})
new LowSync(new JSONFileSync(filename), {})
```

@@ -263,10 +252,9 @@

In-memory adapters. Useful for speeding up unit tests. See [`examples/`](/examples) directory.
In-memory adapters. Useful for speeding up unit tests. See [`src/examples/`](src/examples) directory.
```js
import { Memory, MemorySync } from 'lowdb'
new Low(new Memory())
new LowSync(new MemorySync())
new Low(new Memory(), {})
new LowSync(new MemorySync(), {})
```

@@ -280,4 +268,4 @@

import { LocalStorage, SessionStorage } from 'lowdb/browser'
new LowSync(new LocalStorage(name))
new LowSync(new SessionStorage(name))
new LowSync(new LocalStorage(name), {})
new LowSync(new SessionStorage(name), {})
```

@@ -301,9 +289,17 @@

class AsyncAdapter {
read() { /* ... */ } // should return Promise<data>
write(data) { /* ... */ } // should return Promise<void>
read() {
/* ... */
} // should return Promise<data>
write(data) {
/* ... */
} // should return Promise<void>
}
class SyncAdapter {
read() { /* ... */ } // should return data
write(data) { /* ... */ } // should return nothing
read() {
/* ... */
} // should return data
write(data) {
/* ... */
} // should return nothing
}

@@ -379,4 +375,4 @@ ```

Depending on your use case, this can be fine or not. It can be mitigated by doing batch operations and calling `db.write` only when you need it.
Depending on your use case, this can be fine or not. It can be mitigated by doing batch operations and calling `db.write` only when you need it.
If you plan to scale, it's highly recommended to use databases like PostgreSQL or MongoDB instead.
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