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

web-storage-manager

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web-storage-manager - npm Package Compare versions

Comparing version 1.1.4 to 1.2.0

71

lib/web-storage-manager.js

@@ -1,15 +0,5 @@

require("core-js/modules/es7.symbol.async-iterator");
require("core-js/modules/web.dom.iterable.js");
require("core-js/modules/es6.symbol");
require("core-js/modules/es6.regexp.split.js");
require("core-js/modules/web.dom.iterable");
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
const storage = window.localStorage;

@@ -117,4 +107,3 @@

*
* @param {string} parentKey - parent data key
* @param {string[]} childKeys - data keys - key path
* @param {string} keyPath - key path parentKey.childKey.key
* @param {string} value - data value

@@ -126,4 +115,6 @@ * @param {string} attrCompare - data attrib compare

exports.updateItemInItem = (parentKey, childKeys, value, attrCompare) => {
exports.updateItemInItem = (keyPath, value, attrCompare) => {
try {
const keys = keyPath.split(".");
const parentKey = keys.shift();
const data = storage.getItem(parentKey);

@@ -136,9 +127,5 @@ const r = exports.isDataEncoded(data);

let tmpCollection = {};
childKeys = childKeys.map(k => k.trim()); // iterate through with child keys
const childKeys = keys.map(k => k.trim()); // iterate through with child keys
for (const _ref of childKeys.entries()) {
var _ref2 = _slicedToArray(_ref, 2);
const idx = _ref2[0];
const key = _ref2[1];
for (const [idx, key] of childKeys.entries()) {
if (!collection) return false; // terminate on key not found

@@ -176,7 +163,3 @@

for (const _ref3 of childKeys.reverse().entries()) {
var _ref4 = _slicedToArray(_ref3, 2);
const idx = _ref4[0];
const key = _ref4[1];
for (const [idx, key] of childKeys.reverse().entries()) {
// iterate from last key path first

@@ -210,4 +193,3 @@ let data = tmpCollection[key];

*
* @param {string} parentKey - parent data key
* @param {string[]} childKeys - data keys - key path
* @param {string} keyPath - key path parentKey.childKey.key
* @param {string} value - data value

@@ -219,14 +201,12 @@ * @param {string} attrCompare - data attrib compare

exports.getItemInItem = (parentKey, childKeys, value, attrCompare) => {
exports.getItemInItem = (keyPath, value, attrCompare) => {
try {
const keys = keyPath.split(".");
const parentKey = keys.shift();
let collection = exports.getItem(parentKey);
if (!collection) return false; // terminate process
childKeys = childKeys.map(k => k.trim()); // iterate through with child keys
const childKeys = keys.map(k => k.trim()); // iterate through with child keys
for (const _ref5 of childKeys.entries()) {
var _ref6 = _slicedToArray(_ref5, 2);
const idx = _ref6[0];
const key = _ref6[1];
for (const [idx, key] of childKeys.entries()) {
if (!collection) return false; // terminate on key not found

@@ -258,4 +238,3 @@

*
* @param {string} parentKey - parent data key
* @param {string[]} childKeys - data keys - key path
* @param {string} keyPath - key path parentKey.childKey.key
* @param {string} value - data value

@@ -267,4 +246,6 @@ * @param {string} attrCompare - data attrib compare

exports.removeItemInItem = (parentKey, childKeys, value, attrCompare) => {
exports.removeItemInItem = (keyPath, value, attrCompare) => {
try {
const keys = keyPath.split(".");
const parentKey = keys.shift();
const data = storage.getItem(parentKey);

@@ -276,9 +257,5 @@ const r = exports.isDataEncoded(data);

let tmpCollection = {};
childKeys = childKeys.map(k => k.trim()); // iterate through with child keys
const childKeys = keys.map(k => k.trim()); // iterate through with child keys
for (const _ref7 of childKeys.entries()) {
var _ref8 = _slicedToArray(_ref7, 2);
const idx = _ref8[0];
const key = _ref8[1];
for (const [idx, key] of childKeys.entries()) {
if (!collection) return false; // terminate on key not found

@@ -315,7 +292,3 @@

for (const _ref9 of childKeys.reverse().entries()) {
var _ref10 = _slicedToArray(_ref9, 2);
const idx = _ref10[0];
const key = _ref10[1];
for (const [idx, key] of childKeys.reverse().entries()) {
// iterate from last key path first

@@ -322,0 +295,0 @@ let data = tmpCollection[key];

{
"name": "web-storage-manager",
"version": "1.1.4",
"version": "1.2.0",
"description": "Web utility storage manager to handle save, update and data purge",

@@ -34,4 +34,4 @@ "main": "lib/web-storage-manager.js",

"dependencies": {
"@babel/polyfill": "^7.0.0"
"@babel/polyfill": "^7.4.0"
}
}

@@ -1,7 +0,10 @@

# Web Storage Manager
[![NPM version](https://badge.fury.io/js/web-storage-manager.svg)](http://badge.fury.io/js/web-storage-manager)
Web utility storage manager to handle save, update and data purge
[![NPM](https://nodei.co/npm/web-storage-manager.png?downloads=true&stars=true)](https://nodei.co/npm/web-storage-manager/)
[npm_url]: https://www.npmjs.com/package/web-storage-manager
[![NPM](https://nodei.co/npm-dl/web-storage-manager.png?months=6)](https://nodei.co/npm/web-storage-manager/)
# Web Storage Manager
[web-storage-manager](https://www.npmjs.com/package/web-storage-manager) is a web utility storage manager to handle save, update and data purge.
## Demo

@@ -24,7 +27,7 @@

// update item on key path of previously saved data
const keyPaths = [ 'targetKeyOnParent', 'collection', 'targetObject', 'changethis']
const keyPaths2 = [ 'targetKeyOnParent', 'collection', 'targetObject', 'changethis2']
const keyPath = 'targetKeyOnParent.collection.targetObject.changethis'
const keyPath2 = 'targetKeyOnParent.collection.targetObject.changethis2'
Storage.updateItemInItem('test-sample-parent-key', keyPaths, valueInObj, 'id')
Storage.updateItemInItem('test-sample-parent-key', keyPaths2, valueInObj)
Storage.updateItemInItem(keyPath, valueInObj, 'id')
Storage.updateItemInItem(keyPath2, valueInObj)

@@ -102,10 +105,10 @@ // append item

const keyPaths = [ 'targetKeyOnParent', 'collection', 'targetObject', 'changethis']
Storage.updateItemInItem('test-sample', keyPaths, valueInObj, 'id')
const keyPath = 'targetKeyOnParent.collection.targetObject.changethis'
Storage.updateItemInItem(keyPath, valueInObj, 'id')
const keyPaths2 = [ 'targetKeyOnParent', 'collection', 'targetObject', 'changethis2']
Storage.updateItemInItem('test-sample', keyPaths2, valueInObj)
const keyPath2 = 'targetKeyOnParent.collection.targetObject.changethis2'
Storage.updateItemInItem(keyPath2, valueInObj)
const keyPaths3 = [ 'targetKeyOnParent', 'collection', 'targetObject2']
Storage.updateItemInItem('test-sample', keyPaths3, testItems)
const keyPath3 = 'targetKeyOnParent.collection.targetObject2'
Storage.updateItemInItem(keyPath3, testItems)

@@ -117,4 +120,4 @@ const valueInObj2 = {

}
const keyPaths4 = [ 'targetKeyOnParent', 'collection', 'targetObject2']
Storage.updateItemInItem('test-sample', keyPaths4, valueInObj2)
const keyPath4 = 'targetKeyOnParent.collection.targetObject2'
Storage.updateItemInItem(keyPath4, valueInObj2)

@@ -124,3 +127,3 @@ // append

Storage.removeItemInItem('test-sample', keyPaths, valueInObj, 'id')
Storage.removeItemInItem(keyPath, valueInObj, 'id')

@@ -180,3 +183,3 @@ Storage.setItem('copy', Storage.getItem('test-sample'))

getItem: ƒ (key)
getItemInItem: ƒ (parentKey, childKeys, value, attrCompare)
getItemInItem: ƒ (keyPath, value, attrCompare)
getMultiple: ƒ (keys)

@@ -188,3 +191,3 @@ hasData: ƒ (key)

removeItem: ƒ (key)
removeItemInItem: ƒ (parentKey, childKeys, value, attrCompare)
removeItemInItem: ƒ (keyPath, value, attrCompare)
removeMultiple: ƒ (keys)

@@ -194,3 +197,3 @@ setItem: ƒ (key, value, encoded)

storage: ƒ ()
updateItemInItem: ƒ (parentKey, childKeys, value, attrCompare)
updateItemInItem: ƒ (keyPath, value, attrCompare)

@@ -209,2 +212,2 @@ ```

`Web Storage Manager` is available under the MIT license. See the [LICENSE](https://github.com/nferocious76/web-storage-manager/blob/master/LICENSE) file for more info.
`Web Storage Manager` is available under the MIT license. See the [LICENSE](https://github.com/nferocious76/web-storage-manager/blob/master/LICENSE) file for more info.
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