Socket
Socket
Sign inDemoInstall

electron-json-config

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.3.0

src/utils.js

7

package.json
{
"name": "electron-json-config",
"version": "1.2.0",
"version": "1.3.0",
"description": "Simply set and get configuration from a json file for your Electron app",

@@ -31,5 +31,2 @@ "main": "src/index.js",

"license": "BSD-2-Clause",
"dependencies": {
"exists-file": "^2.0.0"
},
"devDependencies": {

@@ -41,4 +38,4 @@ "electron-mocha": "latest",

"files": [
"src/index.js"
"src/"
]
}
'use strict';
const u = require('./utils.js');
const fs = require('fs');
const exists = require('exists-file');
const electron = require('electron');
const file = (electron.app || electron.remote.app).getPath('userData')+'/config.json';
if(!exists.sync(file)) {
if(!u.exists(file)) {
fs.writeFileSync(file, '{}');

@@ -13,43 +13,2 @@ }

const sync = function() {
fs.writeFileSync(file, JSON.stringify(config));
};
const search = function(object, key) {
let path = key.split('.');
for(let i = 0; i < path.length; i++) {
if(object[path[i]] === undefined) {
return undefined;
}
object = object[path[i]];
}
return object;
};
const set = function(object, key) {
let path = key.split('.');
for(var i = 0; i < path.length - 1; ++i) {
if(!object[path[i]]) {
object[path[i]] = {};
}
object = object[path[i]];
}
return function(object, attribute) {
return function(value) { object[attribute] = value; };
} (object, path[i]);
};
const remove = function(object, key) {
let path = key.split('.');
for(var i = 0; i < path.length - 1; ++i) {
if(!object[path[i]]) {
object[path[i]] = {};
}
object = object[path[i]];
}
return function(object, attribute) {
return function() { delete object[attribute]; };
} (object, path[i]);
};
exports.file = function() {

@@ -60,16 +19,16 @@ return file;

exports.has = function(key) {
return search(config, key) !== undefined;
return u.search(config, key) !== undefined;
};
exports.set = function(key, value) {
set(config, key)(value);
sync();
u.set(config, key)(value);
u.sync(file, config);
};
exports.get = function(key) {
return search(config, key);
return u.search(config, key);
};
exports.keys = function(key) {
return Object.keys((key) ? search(config, key) : config);
return Object.keys((key) ? u.search(config, key) : config);
};

@@ -82,4 +41,4 @@

exports.delete = function(key) {
remove(config, key)();
sync();
u.remove(config, key)();
u.sync(file, config);
};

@@ -89,3 +48,3 @@

config = {};
sync();
u.sync(file, config);
};
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc