Gathering detailed insights and metrics for web-storage-helper
Gathering detailed insights and metrics for web-storage-helper
Gathering detailed insights and metrics for web-storage-helper
Gathering detailed insights and metrics for web-storage-helper
sling-web-storage
A storage helper for the web
react-simple-storage
Simple component and helper functions for using web storage with React.
session-storage-helper-lib
A utility library for simplifying interactions with web's session storage, including complex objects.
@synapsecloud/lib-react
Helper library for web applications built on React Js
npm install web-storage-helper
Typescript
Module System
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
web-storage-helper
is a TypeScript-based library that simplifies working with different types of storage in the browser (like localStorage
, sessionStorage
, cookies
, indexedDB
, and temp
storage). It supports data encryption and ensures safe handling of sensitive information.
localStorage
, sessionStorage
, cookies
, indexedDB
, and temp
storage.You can easily install web-storage-helper
via Yarn:
1yarn add web-storage-helper
To get started, you need to configure the library and set up your encryption key if you plan to use encryption for data storage and retrieval.
1import {configureStorage} from 'web-storage-helper';
2
3// Configure encryption key globally
4configureStorage({ encryptionKey: 'your-secret-key', encodeKey: true });
The storage API is exposed via the storage
object, which contains methods for localStorage
, sessionStorage
, cookies
, indexedDB
, and temp
storage. Additionally, the configure
method is now available directly from the storage
object.
1import storage from 'web-storage-helper';
You can then use the set
, get
, and clear
methods provided for each storage type.
set
)To store data in a specific storage type, you can use the set
method. Data can be stored with or without encryption.
1// Store data in localStorage without encryption 2const saved = storage.local.set('username', 'Atul', false); 3console.log(saved); //true | false 4 5// Store data in sessionStorage with encryption 6const saved = storage.session.set('username', 'Atul', true); 7console.log(saved); //true | false 8 9// Store data in temp storage (will be cleared on page refresh) 10const saved = storage.temp.set('tempData', { key: 'value' }, false); 11console.log(saved); //true | false 12 13// Store data in indexedDB 14const saved = await storage.indexedDB.set('userData', { name: 'Atul', age: 30 }, false); 15console.log(saved); //true | false 16 17// Store data in cookies with encryption 18const saved = storage.cookie.set('authToken', 'your-auth-token', true); 19console.log(saved); //true | false
get
)To retrieve data from any storage type, use the get
method. If encryption was used during storage, you can pass true
to decrypt the data when retrieving it.
1// Get data from localStorage (without encryption) 2const username = storage.local.get('username', false); 3 4// Get data from sessionStorage (with encryption) 5const encryptedUsername = storage.session.get('username', true); 6 7// Get data from temp storage (non-persistent across page refreshes) 8const tempData = storage.temp.get('tempData', false); 9 10// Get data from cookies (with encryption) 11const authToken = storage.cookie.get('authToken', true); 12 13// Get data from indexedDB 14const userData = await storage.indexedDB.get('userData', false);
clear
)To clear data from a storage type, use the clear
method. You can clear a specific key or clear all data from that storage.
1// Clear a specific key from localStorage (without encryption) 2const cleared = storage.local.clear('username', false); 3console.log(cleared); //true | false 4 5// Clear all data from sessionStorage 6const cleared = storage.session.clear(); 7console.log(cleared); //true | false 8 9// Clear a specific encrypted key from cookies 10const cleared = storage.cookie.clear('authToken', true); 11console.log(cleared); //true | false 12 13// Clear all data from indexedDB 14const cleared= await storage.indexedDB.clear(); 15console.log(cleared); //true | false
configureStorage({ encryptionKey:string, encodeKey: boolean })
Configures the encryption key for the library. If encryption is enabled, this key will be used to encrypt and decrypt data.
encryptionKey
(string).set(key: string, value: any, encryption = false)
Stores data in a specified storage type.
true
, encrypts the key and value before storing.get(key: string, encryption = false)
Retrieves data from the specified storage type.
true
, decrypts the value before returning it.clear(key?: string, encryption = false)
Clears data from the specified storage type.
true
, encrypts the key before clearing.1import storage from 'web-storage-helper'; 2 3// Configure encryption key globally 4storage.configure({ encryptionKey: 'secret-key', encodeKey: true }); 5 6// Set encrypted data in localStorage 7storage.local.set('username', 'Atul', true); 8 9// Get encrypted data from localStorage 10const username = storage.local.get('username', true); 11console.log(username); // 'Atul' 12 13// Clear encrypted data from localStorage 14storage.local.clear('username', true); 15 16// Set data in indexedDB 17const saved = await storage.indexedDB.set('username', 'Atul'); 18 19// Get data from localStorage 20const username = await storage.indexedDB.get('username'); 21console.log(username); // 'Atul' 22 23// Clear data from localStorage 24const cleared = await storage.local.clear('username');
We welcome contributions to improve the library! Please fork the repository, create a new branch, and submit a pull request with your changes. Don't forget to add tests for new features or bug fixes.
No vulnerabilities found.
No security vulnerabilities found.