Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-file-object

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-file-object - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

87

index.js
// Generated by CoffeeScript 2.3.1
(function() {
var created_db, erase, find_file, fs, ld, stop, writeFile;
var created_db, erase, find_file, fs, ld, onWrite, stop, stopped, writeFile;

@@ -9,35 +9,31 @@ fs = require('fs');

onWrite = {};
stopped = false;
created_db = {};
module.exports = function({value, file, saveEverySecs, forceNew} = {}) {
module.exports = function({value = {}, file = "json_file_object.json", saveEverySecs = 5, forceNew = false} = {}) {
var error, interval;
if (value == null) {
value = {};
if (created_db[file]) {
throw new Error(`File ${file} in use already`);
}
if (file == null) {
file = "json_file_object.json";
if (!forceNew) {
try {
value = JSON.parse(fs.readFileSync(file, 'utf8'));
} catch (error1) {
error = error1;
console.warn(error);
}
}
if (saveEverySecs == null) {
saveEverySecs = 5;
if (stopped) {
return value;
}
if (forceNew == null) {
forceNew = false;
}
if (!created_db[file]) {
if (!forceNew) {
try {
value = JSON.parse(fs.readFileSync(file, 'utf8'));
} catch (error1) {
error = error1;
console.warn(error);
}
}
interval = setInterval(function() {
return writeFile(file, value);
}, saveEverySecs * 1000);
created_db[file] = {
obj: value,
interval
};
}
interval = setInterval(function() {
return writeFile(file, value);
}, saveEverySecs * 1000);
created_db[file] = {
obj: value,
interval
};
return created_db[file].obj;

@@ -49,4 +45,5 @@ };

if (err) {
return console.log(err);
console.warn(err);
}
return typeof onWrite[file] === "function" ? onWrite[file]() : void 0;
});

@@ -59,4 +56,5 @@ };

if (file) {
writeFile(file, created_db[file].obj);
return stop(file);
return onWrite[file] = function() {
return stop(file);
};
}

@@ -67,6 +65,11 @@ };

var file, results;
if (stopped) {
return;
}
stopped = true;
results = [];
for (file in created_db) {
writeFile(file, created_db[file].obj);
results.push(stop(file));
results.push(onWrite[file] = function() {
return stop(file);
});
}

@@ -80,3 +83,5 @@ return results;

if (file) {
return erase(file);
return onWrite[file] = function() {
return erase(file);
};
}

@@ -87,5 +92,8 @@ };

var file, results;
stopped = true;
results = [];
for (file in created_db) {
results.push(erase(file));
results.push(onWrite[file] = function() {
return erase(file);
});
}

@@ -99,3 +107,4 @@ return results;

clearInterval(interval);
return delete created_db[file];
delete created_db[file];
return delete onWrite[file];
};

@@ -105,3 +114,7 @@

stop(file);
return fs.unlink(file);
return fs.unlink(file, function(err) {
if (err) {
return console.warn(err);
}
});
};

@@ -108,0 +121,0 @@

{
"name": "json-file-object",
"version": "2.0.0",
"version": "2.0.1",
"description": "periodically persisting JSON-able objects into files (one per object)",

@@ -15,3 +15,3 @@ "main": "index.js",

"author": "Wojciech Fraczak",
"license": "GPL",
"license": "MIT",
"devDependencies": {

@@ -21,4 +21,4 @@ "coffeescript": "^2.3.1"

"dependencies": {
"lodash": "^4.17.10"
"lodash": "^4.17.15"
}
}

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