browser-storage-plus
v1.0.4
Published
Enhanced wrapper for localStorage/sessionStorage with additional features like type safety, expiration, encryption, and events
Maintainers
Readme
Browser Storage Plus
Installation
yarn add browser-storage-plusor
npm i browser-storage-plusFeatures
- 🔄 Simple API similar to standard Storage
- ⏱️ Time-to-live (TTL) functionality for keys
- 🔒 Optional key encryption
- 🔄 Works with both localStorage and sessionStorage
- 📦 Tiny size with minimal dependencies
Usage
import { MStorage } from "browser-storage-plus";
// Create a storage instance
const storage = new MStorage({
storage: "local" // "local" or "session", default "local"
encryptKeys: false // set to true to encrypt keys
});
// Set a value
storage.set('user', "Maut");
// Set a value with TTL in seconds
storage.set('auth_token', "xyz123", 3600);
// Get a value
const user = storage.get('user'); // 'Maut'
// Check remaining TTL (in seconds)
const tokenTtl = storage.ttl('auth_token');
// Remove a value
storage.remove(['user', 'auth_token']);