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

jsonfile-obj-db

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonfile-obj-db - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

BaseClass.js

70

main.js

@@ -1,69 +0,1 @@

const jsonfile = require( "jsonfile" );
var WC = {
_DB_NAME: null ,
_DB_PATH: null ,
self: {} ,
open: function( wConfig ) {
if ( !wConfig ) {
var xP = process.argv[ 1 ].split( "/" );
xP.pop();
WC._DB_NAME = "_id_" + Math.random().toString( 36 ).substr( 2 , 7 );
WC._DB_PATH = xP.join("/") + "/" + WC._DB_NAME + ".json";
WC.save();
return;
}
var isCFGaOBJ = typeof wConfig === "object" ? true : false;
if ( !isCFGaOBJ ) { var x1 = wConfig; wConfig = {}; wConfig.path = x1; }
var xN , xP = null;
var xT1 = wConfig.path.split("/").length;
if ( xT1 > 1 ) {
xN = wConfig.path.split("/"); xN = xN.pop(); xN = xN.split(".json")[0];
xP = wConfig.path;
}
else {
xN = wConfig.path;
xP = process.argv[ 1 ].split( "/" ); xP.pop(); xP = xP.join("/") + "/" + xN + ".json";
}
if ( xP.indexOf(".json") === -1 ) { xP = xP + ".json"; }
WC._DB_NAME = xN;
WC._DB_PATH = xP;
try { WC.self = jsonfile.readFileSync( WC._DB_PATH ); }
catch( error ) {
if ( wConfig.skeleton ) {
WC.self = wConfig.skeleton;
}
else {
WC.self = {};
}
WC.save();
}
},
save: function() { jsonfile.writeFileSync( WC._DB_PATH , WC.self ); },
edit: function( ...args ) {
// https://stackoverflow.com/questions/16533384/javascript-assign-value-to-element-in-nested-object-without-knowing-level
var x1 = args;
var wNV = x1.pop();
function recReplace( o , i ) {
var ii = i.shift();
if ( i.length == 0 ) {
if ( !o[ ii ] ) { o[ ii ] = {}; }
o[ ii ] = wNV;
}
else {
if ( !o[ ii ] ) { o[ ii ] = {}; }
o[ ii ] = recReplace( o[ ii ] , i );
}
return o;
}
WC.self = recReplace( WC.self , x1 );
WC.save();
}
};
module.exports = WC;
module.exports = require( "./BaseClass.js" );
{
"name": "jsonfile-obj-db",
"version": "1.0.7",
"version": "1.0.8",
"description": "",

@@ -13,2 +13,3 @@ "main": "main.js",

},
"url": "https://github.com/ceberous/jsonfile-obj-db",
"author": "",

@@ -15,0 +16,0 @@ "license": "ISC",

# jsonfile-obj-db
```javascript
var MyOBJ_DB = require( "jsonfile-obj-db" );
MyOBJ_DB.open( "myCustomOBJName" );
MyOBJ_DB[ "self" ][ "random" ] = {
some: "obj",
array: ["asfdsas" , 1 , 3]
};
console.log( MyOBJ_DB.self );
MyOBJ_DB.save();
```
const JFODB = require( "jsonfile-obj-db" );
( ()=> {
```javascript
var My_OBJ_DB_1 = require( "jsonfile-obj-db ");
MY_OBJ_DB_1.open( "myCustomOBJName" );
console.log( MyOBJ_DB.self );
```
const my_db_1 = new JFODB( "test1" );
const my_db_2 = new JFODB( "test2" );
my_db_1.self[ "1" ] = [ "1" , 2 , [ 3 , 5 ] ];
my_db_1.save();
my_db_2.self[ "2" ] = "test";
my_db_2.save();
})();
```
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