node-json-db
Advanced tools
Comparing version
@@ -13,3 +13,3 @@ (function () { | ||
var JsonDB = function (filename, saveOnPush) { | ||
var JsonDB = function (filename, saveOnPush, humanReadable) { | ||
@@ -36,3 +36,9 @@ this.filename = filename; | ||
} | ||
this.saveOnPush = saveOnPush; | ||
this.saveOnPush = saveOnPush || true; | ||
if (humanReadable) { | ||
this.humanReadable = humanReadable; | ||
} | ||
else { | ||
this.humanReadable = false; | ||
} | ||
@@ -177,3 +183,8 @@ return this; | ||
try { | ||
data = JSON.stringify(this.data); | ||
if (this.humanReadable) { | ||
data = JSON.stringify(this.data, null, 4); | ||
} | ||
else { | ||
data = JSON.stringify(this.data); | ||
} | ||
FS.writeFileSync(this.filename, data, 'utf8'); | ||
@@ -180,0 +191,0 @@ } catch (err) { |
{ | ||
"name": "node-json-db", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Database using JSON file as storage for Node.JS", | ||
@@ -5,0 +5,0 @@ "main": "./JsonDB.js", |
@@ -41,3 +41,4 @@ [](http://travis-ci.org/Belphemur/node-json-db) [](https://coveralls.io/r/Belphemur/node-json-db?branch=master) | ||
//If you put false, you'll have to call the save() method. | ||
var db = new JsonDB("myDataBase", true); | ||
//The third argument is to ask JsonDB to save the database in an human readable format. (default false) | ||
var db = new JsonDB("myDataBase", true, false); | ||
@@ -44,0 +45,0 @@ //Pushing the data into the database |
@@ -33,3 +33,3 @@ var expect = require("expect.js"); | ||
describe('Initialisation', function () { | ||
var db = new JsonDB(testFile1, true); | ||
var db = new JsonDB(testFile1, true, true); | ||
@@ -36,0 +36,0 @@ it('should create the JSON File', function (done) { |
26790
1.72%491
2.29%140
0.72%