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

Web utility storage manager to handle save, update and data purge

  • 3.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-91.07%
Maintainers
1
Weekly downloads
 
Created
Source

NPM

Web Storage Manager

web-storage-manager is a web utility storage manager to handle save, update and data purge.

Installation


npm i web-storage-manager --save

Imports


import { LocalStorage, SessionStorage, EncodedLocalStorage, EncodedSessionStorage } from 'web-storage-manager';

or using helper


import { createLocalStorage, createSessionStorage } from 'web-storage-manager';

// Options conforms to:
/*
interface Options {
    delimiter?: string,
    isEncoded: boolean
}
*/

// createLocalStorage(window, options)
const LocalStorage = createLocalStorage(window, { isEncoded: false });
const SessionStorage = createSessionStorage(window, { isEncoded: false });
const EncodedLocalStorage = createLocalStorage(window, { isEncoded: true });
const EncodedSessionStorage = createSessionStorage(window, { isEncoded: true });

or using the base class


import { WebStorage, EncodedWebStore } from 'web-storage-manager';

// both class has a constructor:
// constructor(storage: Storage, delimiter: string = '.')

const LocalStorage = new WebStorage(window.localStorage, delimiter);
const SessionStorage = new WebStorage(window.sessionStorage, delimiter);

const EncodedLocalStorage = new EncodedWebStore(window.localStorage, delimiter);
const EncodedSessionStorage = new EncodedWebStore(window.sessionStorage, delimiter);

Usage and Examples

Please refer to test files local.test.js and session.test.js for a complete sample and usage.


WebStorage.setItem('sampleKey', 'sampleValue');

const testObject = {
    nestedKey: {
        nestedKeyA: 'nestedKeyA-target-value',
        nestedKeyB: {
            nestedKeyC: { itemKey: 'itemKey-value', itemKey2: 'itemKey2-target-value' },
            nestedKeyD: [{ id: 'id1' }, { id: 'id2' }, { id: 'id3' }, { id: 'idz' }]
        }
    }
};

const isSuccess = WebStorage.setItem('testKey', testObject);
// expected result: true

const item2 = WebStorage.getItemInItem('testKey.nestedKey.nestedKeyA');
// expected result: nestedKeyA-target-value

Available Functions


key: ƒ key(n)
length: ƒ length()
setItem: ƒ setItem(key, value)
getItem: ƒ getItem(key)
clear: ƒ clear()
getItemInItem: ƒ getItemInItem(key, attrCompare)
getMultipleItems: ƒ getMultipleItems(keys)
appendItemInItem: ƒ appendItemInItem(key, value)
setMultipleItems: ƒ setMultipleItems(items)
updateItemInItem: ƒ updateItemInItem(key, attrCompare, newValue)
removeItem: ƒ removeItem(key)
removeItemInItem: ƒ removeItemInItem(key, attrCompare)
removeMultipleItems: ƒ removeMultipleItems(keys)

Unit Test

Screenshot 2023-06-28 at 6 12 02 PM

Contribute

We would love for you to contribute to Web Storage Manager. See the LICENSE file for more info.

About

This project was inpired by 'react-persist' that I felt lacking of the functionalities that I need that I decided to create my own on top of Storage API. This project has grown and had a major revamp in its version 3.

License

Web Storage Manager is available under the MIT license. See the LICENSE file for more info.

Keywords

FAQs

Package last updated on 29 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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