Registry / storage / web-storage-es6

web-storage-es6

JSON →
library1.2.0jsnpmunverified

web-storage-es6 is a lightweight ES6 library that provides an abstraction layer over the HTML5 web storage APIs (localStorage and sessionStorage) plus an in-memory global storage. Version 1.2.0 is the current stable release. It offers namespace isolation, batch operations (populate/append), and fallback defaults. Unlike raw storage APIs, it serializes objects automatically and prevents common pitfalls like repetitive writes. The library has minimal overhead and no external dependencies, making it suitable for browser-based projects where a simple, predictable storage wrapper is needed over alternatives like localForage or store.js.

npm install web-storage-es6
INSTALL
IMPORT
SIG · WEB-STORAGE-ES6
W
web-storage-es6
storagejavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import WebStorageES6 from 'web-storage-es6'
✗ import { WebStorageES6 } from 'web-storage-es6'
The library exports a single class as default export. Named import will result in undefined.
require
✓ const WebStorageES6 = require('web-storage-es6')
✗ const { WebStorageES6 } = require('web-storage-es6')
CommonJS require returns the class directly; destructuring is incorrect.
Storage instances
✓ const local = new WebStorageES6('Local')
✗ const local = new WebStorageES6('localStorage')
The storage type must be the string 'Local', 'Session', or 'Global' (case-sensitive).

Demonstrates all major storage operations: create instances of Local, Session, Global storage; set, get, check, populate, append, forget, flush, pull, and retrieve all data.

import WebStorageES6 from 'web-storage-es6'; // Create a local storage with 'default' namespace const localStorage = new WebStorageES6('Local'); // Create a session storage const sessionStorage = new WebStorageES6('Session'); // Create a global storage with a custom namespace const globalStorage = new WebStorageES6('Global', 'custom'); // Set values localStorage.put('key1', 'value1'); // Get with default const value = localStorage.get('key1', 'default'); // Check existence if (localStorage.has('key1')) { console.log('key1 exists'); } // Bulk populate localStorage.populate({ a: 1, b: 2 }); // Append localStorage.append({ c: 3 }); // Remove localStorage.forget('key1'); // Clear all namespaced data localStorage.flush(); // Pull (get and remove) const pulled = localStorage.pull('a', 'nope'); // Get all data const all = localStorage.all(); console.log(all); // { b: 2, c: 3 }
Debug
Known issues
gotchaStorage type names are case-sensitive and must be exactly 'Local', 'Session', or 'Global'. Typing 'localStorage' or 'session' will fail silently or throw an error.
fix
Use the exact strings: 'Local', 'Session', 'Global'.
affects: all
deprecatedThe package uses internal methods like _setData and _getData which are marked protected and may change without notice.
fix
Do not rely on underscore-prefixed methods; use public API only.
affects: all
gotchaThe 'Global' storage stores data on the global window object under the namespace key. It does not survive page reloads and memory is not cleared unless flushed.
fix
Use 'Global' only for temporary single-page data. Consider 'Local' or 'Session' for persistence.
affects: all
gotchaValues are serialized via JSON.stringify and deserialized via JSON.parse. Non-JSON-serializable values (e.g., Functions, Symbols, circular references) will fail.
fix
Only store JSON-serializable data (strings, numbers, objects, arrays, booleans, null).
affects: all
gotchaThe library was originally written in ES6 and may require a polyfill for Object.assign or Promise in very old browsers.
fix
Use a polyfill or transpile with Babel for IE11 and below.
affects: all
Errors
Common errors & fixes
TypeError: WebStorageES6 is not a constructor
Wrong import pattern: using named import instead of default import, or destructuring require.
fix
Correct import: import WebStorageES6 from 'web-storage-es6' or const WebStorageES6 = require('web-storage-es6').
Error: Invalid storage type.
Passing an incorrect string for storage type, e.g., 'localStorage' instead of 'Local'.
fix
Use one of: 'Local', 'Session', 'Global'.
TypeError: storage.get is not a function
Calling methods on the class itself instead of an instance.
fix
Create an instance first: const store = new WebStorageES6('Local'); then call store.get().
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
38 hits · last 30 days
node
36
Resources
web-storage-es6 — npm install web-storage-es6 · libregistry