web-storage-manager
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "web-storage-manager", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Web utility storage manager to handle save, update and data purge", | ||
"main": "src/web-storage-manager.js", | ||
"scripts": { | ||
"test": "jest --env=jsdom" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "webpack --watch", | ||
"build": "webpack" | ||
}, | ||
@@ -16,3 +18,5 @@ "repository": { | ||
"local", | ||
"storage" | ||
"storage", | ||
"local storage", | ||
"web storage" | ||
], | ||
@@ -19,0 +23,0 @@ "author": "Neil Francis Ramirez Hipona", |
@@ -156,3 +156,3 @@ # Web Storage Manager | ||
This project was inpired by 'react-persist' that lacks feature. | ||
This project was inpired by 'react-persist' that was discontinued. | ||
@@ -159,0 +159,0 @@ ## License |
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
const storage = window.localStorage | ||
@@ -12,3 +10,3 @@ | ||
* @param {string} key - data key | ||
* @param {string} value - data value | ||
* @param {*} value - data value | ||
* | ||
@@ -31,3 +29,3 @@ */ | ||
* @param {string} items[].item.key - data key | ||
* @param {string} items[].item.value - data value | ||
* @param {*} items[].item.value - data value | ||
* | ||
@@ -51,3 +49,3 @@ */ | ||
* @param {string} key - data key | ||
* @param {string} value - data value | ||
* @param {*} value - data value | ||
* | ||
@@ -59,7 +57,4 @@ */ | ||
const oldData = this.getItem(key) | ||
const newData = { | ||
...oldData, | ||
...value | ||
} | ||
let newData = this.combineObject(value, oldData); | ||
this.setItem(key, newData) | ||
@@ -75,2 +70,35 @@ | ||
* | ||
* @param {Object} object - object to combine | ||
* @param {Object} toObject - object to combine to | ||
* | ||
*/ | ||
exports.combineObject = (object, toObject) => { | ||
for (const key in object) { | ||
toObject[key] = object[key] | ||
} | ||
return toObject | ||
} | ||
/** | ||
* | ||
* @param {Object[]} collection - collection of objects | ||
* @param {Object} object - object to find index from the collection | ||
* @param {string} attr - attribute of the object to compare to | ||
* | ||
*/ | ||
exports.indexOfObject = (collection, object, attr) => { | ||
for (let i = 0; i < collection.length; i++) { | ||
if (collection[i][attr] === object[attr]) { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} | ||
/** | ||
* | ||
* @param {string} parentKey - parent data key | ||
@@ -100,3 +128,3 @@ * @param {string[]} childKeys - data keys - key path | ||
// collection | ||
const idx = indexOfObject(collection, value, attrCompare) | ||
const idx = attrCompare ? this.indexOfObject(collection, value, attrCompare) : -1 | ||
@@ -141,8 +169,5 @@ // append or replace object at index | ||
// update with old data + new data | ||
// update with old data + new data | ||
newCollection = { | ||
[key]: { | ||
...data, | ||
...newCollection | ||
} | ||
[key]: objSelf.combineObject(newCollection, data) | ||
} | ||
@@ -153,6 +178,3 @@ } | ||
// add modified data to the parent collection | ||
newCollection = { | ||
...oldCollection, | ||
...newCollection, | ||
} | ||
newCollection = objSelf.combineObject(newCollection, oldCollection) | ||
@@ -167,14 +189,2 @@ // save and update local | ||
// Collection ~ Ojbect ~ attribute | ||
function indexOfObject(collection, object, attr) { | ||
for (let i = 0; i < collection.length; i++) { | ||
if (collection[i][attr] === object[attr]) { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} | ||
} catch (error) { | ||
@@ -186,2 +196,4 @@ return false | ||
/** | ||
@@ -188,0 +200,0 @@ * |
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
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
12293
6
247
1