informa-db.js
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -1,2 +0,2 @@ | ||
import * as DbUtils from './utils.js'; // eslint-disable-line import/extensions | ||
import DbUtils from './utils.js'; // eslint-disable-line import/extensions | ||
@@ -77,2 +77,2 @@ if (!window) throw new Error('Running in the wrong environment (Did not find window)'); | ||
module.exports = { Db, DbUtils }; | ||
export default { Db, DbUtils }; |
{ | ||
"name": "informa-db.js", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "DataBases made easier", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
@@ -24,26 +24,2 @@ const fs = require('fs'); | ||
genProxy(data) { | ||
return new Proxy(data, { | ||
set: (obj, prop, val) => { | ||
obj[prop] = val; | ||
if (this.saveOnChange) { | ||
this.update(); | ||
} | ||
return true; | ||
}, | ||
deleteProperty: (obj, prop) => { | ||
delete obj[prop]; | ||
if (this.saveOnChange) { | ||
this.update(); | ||
} | ||
return true; | ||
}, | ||
get: (obj, prop) => ( | ||
typeof obj[prop] === 'object' && obj[prop] | ||
? this.genProxy(obj[prop]) | ||
: obj[prop] | ||
), | ||
}); | ||
} | ||
/** | ||
@@ -75,3 +51,3 @@ * async Updates the file/db from this.readOnlyValue | ||
get value() { | ||
return this.genProxy(this.readOnlyValue); | ||
return DbUtils.genProxy(this.readOnlyValue, this.saveOnChange, this.update); | ||
} | ||
@@ -78,0 +54,0 @@ } |
25
utils.js
@@ -1,2 +0,2 @@ | ||
module.exports = { | ||
export default { | ||
setAllTo(db, setTo) { | ||
@@ -6,2 +6,25 @@ Object.keys(db).forEach((k) => delete db[k]); | ||
}, | ||
genProxy(data, saveOnChange, update) { | ||
return new Proxy(data, { | ||
set: (obj, prop, val) => { | ||
obj[prop] = val; | ||
if (saveOnChange) { | ||
update(); | ||
} | ||
return true; | ||
}, | ||
deleteProperty: (obj, prop) => { | ||
delete obj[prop]; | ||
if (saveOnChange) { | ||
update(); | ||
} | ||
return true; | ||
}, | ||
get: (obj, prop) => ( | ||
typeof obj[prop] === 'object' && obj[prop] | ||
? this.genProxy(obj[prop]) | ||
: obj[prop] | ||
), | ||
}); | ||
}, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10126