web-storage-manager
Advanced tools
Comparing version 1.0.21 to 1.0.22
@@ -172,3 +172,4 @@ require("core-js/modules/es7.symbol.async-iterator"); | ||
try { | ||
let collection = null; | ||
let oldCollection = null; // get old collection | ||
const data = storage.getItem(parentKey); | ||
@@ -178,9 +179,10 @@ const r = this.isDataEncoded(data); | ||
if (r === 1) { | ||
collection = JSON.parse(data); | ||
oldCollection = JSON.parse(data); | ||
} else if (r === 0) { | ||
collection = this.decode(data); | ||
oldCollection = this.decode(data); | ||
} | ||
if (!collection) return false; // terminate process | ||
if (!oldCollection) return false; // terminate process | ||
let collection = oldCollection; | ||
let tmpCollection = {}; | ||
@@ -204,3 +206,3 @@ childKeys = childKeys.map(k => k.trim()); // iterate through with child keys | ||
// collection | ||
const idx = attrCompare ? this.indexOfObject(collection, value, attrCompare) : -1; // append or replace object at index | ||
const idx = attrCompare ? exports.indexOfObject(collection, value, attrCompare) : -1; // append or replace object at index | ||
@@ -216,3 +218,3 @@ if (idx >= 0) { | ||
tmpCollection[key] = collection; | ||
mapDataUpdate(this, tmpCollection); | ||
mapDataUpdate(tmpCollection); | ||
} else { | ||
@@ -225,7 +227,3 @@ // add to temp collection | ||
function mapDataUpdate(self, tmpCollection) { | ||
const objSelf = Object(self); // set self | ||
const oldCollection = objSelf.getItem(parentKey); // get old collection | ||
const mapDataUpdate = tmpCollection => { | ||
let newCollection = null; | ||
@@ -249,3 +247,3 @@ | ||
newCollection = { | ||
[key]: objSelf.combineObject(newCollection, data) | ||
[key]: exports.combineObject(newCollection, data) | ||
}; | ||
@@ -256,12 +254,12 @@ } | ||
// add modified data to the parent collection | ||
newCollection = objSelf.combineObject(newCollection, oldCollection); // save and update local | ||
newCollection = exports.combineObject(newCollection, oldCollection); // save and update local | ||
if (r === 1) { | ||
return objSelf.setEncodeItem(parentKey, newCollection); | ||
return exports.setEncodeItem(parentKey, newCollection); | ||
} else if (r === 0) { | ||
return objSelf.setItem(parentKey, newCollection); | ||
return exports.setItem(parentKey, newCollection); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} catch (error) { | ||
@@ -331,3 +329,3 @@ throw error; | ||
const data = storage.getItem(key); | ||
const r = this.isDataEncoded(data); | ||
const r = exports.isDataEncoded(data); | ||
@@ -337,3 +335,3 @@ if (r === 1) { | ||
} else if (r === 0) { | ||
collection = this.decode(data); | ||
collection = exports.decode(data); | ||
} | ||
@@ -359,3 +357,3 @@ | ||
// collection | ||
const idx = attrCompare ? this.indexOfObject(collection, value, attrCompare) : -1; // remove object at index | ||
const idx = attrCompare ? exports.indexOfObject(collection, value, attrCompare) : -1; // remove object at index | ||
@@ -372,3 +370,3 @@ if (idx >= 0) { | ||
mapDataUpdate(this, tmpCollection); | ||
mapDataUpdate(tmpCollection); | ||
} else { | ||
@@ -381,7 +379,5 @@ // add to temp collection | ||
function mapDataUpdate(self, tmpCollection) { | ||
const objSelf = Object(self); // set self | ||
function mapDataUpdate(tmpCollection) { | ||
const oldCollection = exports.getItem(parentKey); // get old collection | ||
const oldCollection = objSelf.getItem(parentKey); // get old collection | ||
let newCollection = null; | ||
@@ -405,3 +401,3 @@ | ||
newCollection = { | ||
[key]: objSelf.combineObject(newCollection, data) | ||
[key]: exports.combineObject(newCollection, data) | ||
}; | ||
@@ -412,8 +408,8 @@ } | ||
// add modified data to the parent collection | ||
newCollection = objSelf.combineObject(newCollection, oldCollection); // save and update local | ||
newCollection = exports.combineObject(newCollection, oldCollection); // save and update local | ||
if (r === 1) { | ||
return objSelf.setEncodeItem(parentKey, newCollection); | ||
return exports.setEncodeItem(parentKey, newCollection); | ||
} else if (r === 0) { | ||
return objSelf.setItem(parentKey, newCollection); | ||
return exports.setItem(parentKey, newCollection); | ||
} | ||
@@ -420,0 +416,0 @@ } |
{ | ||
"name": "web-storage-manager", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"description": "Web utility storage manager to handle save, update and data purge", | ||
@@ -5,0 +5,0 @@ "main": "lib/web-storage-manager.js", |
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
19045
466