web-storage-manager
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -108,17 +108,10 @@ require("core-js/modules/es7.symbol.async-iterator"); | ||
const r = exports.isDataEncoded(data); | ||
let collection = {}; | ||
const collection = r[1]; | ||
if (!collection) return; // return as we don't know what format the data should be saved | ||
if (r === 1) { | ||
collection = exports.decode(data); | ||
} else if (r === 0) { | ||
collection = JSON.parse(data); | ||
} else { | ||
return false; | ||
} | ||
const newData = exports.combineObject(value, collection); | ||
if (r === 1) { | ||
if (r[0] === 1) { | ||
return exports.setEncodeItem(key, newData); | ||
} else if (r === 0) { | ||
} else if (r[0] === 0) { | ||
return exports.setItem(key, newData); | ||
@@ -177,16 +170,8 @@ } | ||
try { | ||
let oldCollection = null; // get old collection | ||
const data = storage.getItem(parentKey); | ||
const r = exports.isDataEncoded(data); | ||
let collection = r[1]; // get old collection | ||
if (r === 1) { | ||
oldCollection = exports.decode(data); | ||
} else if (r === 0) { | ||
oldCollection = JSON.parse(data); | ||
} | ||
if (!collection) return false; // terminate process | ||
if (!oldCollection) return false; // terminate process | ||
let collection = oldCollection; | ||
let tmpCollection = {}; | ||
@@ -254,7 +239,7 @@ childKeys = childKeys.map(k => k.trim()); // iterate through with child keys | ||
// add modified data to the parent collection | ||
newCollection = exports.combineObject(newCollection, oldCollection); // save and update local | ||
newCollection = exports.combineObject(newCollection, r[1]); // save and update local | ||
if (r === 1) { | ||
if (r[0] === 1) { | ||
return exports.setEncodeItem(parentKey, newCollection); | ||
} else if (r === 0) { | ||
} else if (r[0] === 0) { | ||
return exports.setItem(parentKey, newCollection); | ||
@@ -327,12 +312,5 @@ } | ||
try { | ||
let collection = null; | ||
const data = storage.getItem(parentKey); | ||
const r = exports.isDataEncoded(data); | ||
if (r === 1) { | ||
collection = exports.decode(data); | ||
} else if (r === 0) { | ||
collection = JSON.parse(data); | ||
} | ||
let collection = r[1]; | ||
if (!collection) return false; // terminate process | ||
@@ -377,4 +355,2 @@ | ||
function mapDataUpdate(tmpCollection) { | ||
const oldCollection = exports.getItem(parentKey); // get old collection | ||
let newCollection = null; | ||
@@ -404,3 +380,3 @@ | ||
// add modified data to the parent collection | ||
newCollection = exports.combineObject(newCollection, oldCollection); // save and update local | ||
newCollection = exports.combineObject(newCollection, r[1]); // save and update local | ||
@@ -430,10 +406,3 @@ if (r === 1) { | ||
const r = exports.isDataEncoded(data); | ||
if (r === 1) { | ||
return exports.decode(data); | ||
} else if (r === 0) { | ||
return JSON.parse(data); | ||
} else { | ||
return data; | ||
} | ||
return r[1]; | ||
} catch (error) { | ||
@@ -446,3 +415,4 @@ throw error; | ||
* @param {object} data - data to be validated | ||
* | ||
* @return {object[]} - [0] status, [1] data | ||
* | ||
*/ | ||
@@ -452,8 +422,11 @@ | ||
exports.isDataEncoded = data => { | ||
if (exports.decode(data)) { | ||
return 1; | ||
let d = exports.decode(data); | ||
if (d) { | ||
return [1, d]; | ||
} else if (data.startsWith('{') && data.endsWith('}')) { | ||
return 0; | ||
d = JSON.parse(data); | ||
return [0, d]; | ||
} else { | ||
return -1; // if data is null | ||
return [-1, null]; | ||
} | ||
@@ -474,6 +447,6 @@ }; | ||
const data = storage.getItem(key); | ||
const item = JSON.parse(data); | ||
const r = exports.isDataEncoded(data); | ||
if (item) { | ||
items.push(item); | ||
if (r[1]) { | ||
items.push(r[1]); | ||
} | ||
@@ -480,0 +453,0 @@ } |
{ | ||
"name": "web-storage-manager", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"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
215873
448