Registry / storage / memorystorage

memorystorage

JSON →
library0.12.0jsnpmunverified

MemoryStorage is a JavaScript library (v0.12.0) that provides an in-memory implementation of the Web Storage API (localStorage/sessionStorage). It serves as a drop-in replacement for environments where the native Web Storage API is unavailable, such as older browsers or server-side Node.js. The library supports both isolated (namespaced) and shared storage instances, follows the W3C specification, and is distributed as a UMD module compatible with CommonJS, AMD, and ES modules. It is lightweight (~2KB minified), has no dependencies, and is maintained by the Download organization on GitHub.

npm install memorystorage
INSTALL
IMPORT
SIG · MEMORYSTORAGE
M
memorystorage
storagejavascriptv0.12.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.

MemoryStorage
✓ import MemoryStorage from 'memorystorage'
✗ const { MemoryStorage } = require('memorystorage')
Default import. CommonJS require returns the constructor directly; destructuring fails.
MemoryStorage
✓ const MemoryStorage = require('memorystorage')
CommonJS require works but note that the package exports a single function, not an object with a MemoryStorage property.
MemoryStorage
✓ define(['memorystorage'], function(MemoryStorage) { ... })
AMD module usage for RequireJS.

Create MemoryStorage instances (shared or isolated) and demonstrate basic Web Storage API operations.

import MemoryStorage from 'memorystorage'; // Create a globally shared storage instance const store = MemoryStorage(); store.setItem('key', 'value'); console.log(store.getItem('key')); // 'value' // Create an isolated storage instance with a namespace const isolated = new MemoryStorage('my-app'); console.log(isolated.length); // 0 // All Web Storage API methods are supported: store.removeItem('key'); store.clear(); console.log(store.key(0)); // null
Debug
Known issues
gotchaMemoryStorage can be called with or without 'new'. Both work.
fix
Use either 'new MemoryStorage()' or 'MemoryStorage()'.
affects: all
gotchaThe 'id' property is immutable; assignment is silently ignored in non-strict mode.
fix
Do not attempt to overwrite the 'id' property after construction.
affects: all
Errors
Common errors & fixes
TypeError: MemoryStorage is not a constructor
Importing incorrectly (e.g., using named import instead of default).
fix
Use 'import MemoryStorage from 'memorystorage'' or 'const MemoryStorage = require('memorystorage')'.
TypeError: store.setItem is not a function
If MemoryStorage was imported as an object with a property named 'MemoryStorage', but it's directly the constructor.
fix
Ensure you use default import: 'import MemoryStorage from 'memorystorage''.
Upgrade
Version history
0.12.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
24
Amazon
1
Resources
memorystorage — npm install memorystorage · libregistry