simple-json-db
Advanced tools
Comparing version
11
index.js
@@ -5,7 +5,8 @@ const fs = require("fs"); | ||
* Default configuration values. | ||
* @type {{asyncWrite: boolean, syncOnWrite: boolean}} | ||
* @type {{asyncWrite: boolean, syncOnWrite: boolean, jsonSpaces: number}} | ||
*/ | ||
const defaultOptions = { | ||
asyncWrite: false, | ||
syncOnWrite: true | ||
syncOnWrite: true, | ||
jsonSpaces: 4 | ||
}; | ||
@@ -33,2 +34,4 @@ | ||
* @param {boolean} [options.syncOnWrite] Makes the storage be written to disk after every modification. Enabled by default. | ||
* @param {boolean} [options.syncOnWrite] Makes the storage be written to disk after every modification. Enabled by default. | ||
* @param {number} [options.jsonSpaces] How many spaces to use for indentation in the output json files. Default = 4 | ||
* @constructor | ||
@@ -146,3 +149,3 @@ */ | ||
if (this.options && this.options.asyncWrite) { | ||
fs.writeFile(this.filePath, JSON.stringify(this.storage, null, 4), (err) => { | ||
fs.writeFile(this.filePath, JSON.stringify(this.storage, null, this.options.jsonSpaces), (err) => { | ||
if (err) throw err; | ||
@@ -152,3 +155,3 @@ }); | ||
try { | ||
fs.writeFileSync(this.filePath, JSON.stringify(this.storage, null, 4)); | ||
fs.writeFileSync(this.filePath, JSON.stringify(this.storage, null, this.options.jsonSpaces)); | ||
} catch (err) { | ||
@@ -155,0 +158,0 @@ if (err.code === 'EACCES') { |
{ | ||
"name": "simple-json-db", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A simple, no-frills, JSON storage engine for Node.JS", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"engines": { | ||
@@ -7,0 +8,0 @@ "node": ">=6.0" |
@@ -31,2 +31,3 @@ # Simple JSONdb [](https://www.npmjs.com/package/simple-json-db) [](https://www.npmjs.com/package/simple-json-db) [](https://www.npmjs.com/package/simple-json-db) [](https://libraries.io/npm/simple-json-db/dependents) [](https://snyk.io/vuln/search?q=simple-json-db&type=npm) | ||
| syncOnWrite | _Boolean_ | Makes the storage be written to disk after every modification. | _**true**_ | | ||
| jsonSpaces | _Number_ | The number of spaces used for indentation in the output JSON. | _**4**_ | | ||
@@ -33,0 +34,0 @@ ### Set a key |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15178
5.96%7
16.67%293
5.02%72
1.41%0
-100%