Registry / storage / key-storage

key-storage

JSON →
library1.0.1jsnpmunverified

A simple client-side storage wrapper that uses localStorage with automatic fallback to cookies when localStorage is unavailable. Version 1.0.1 appears stable with infrequent updates. Differentiates from other storage libraries by its minimal API and use of a Node.js require-style module pattern, though it is designed exclusively for browsers, not Node.js. It supports basic get/set/remove operations but lacks advanced features like expiration, serialization, or namespacing.

npm install key-storage
INSTALL
IMPORT
SIG · KEY-STORAGE
K
key-storage
storagejavascriptv1.0.1
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
var storage = require('key-storage');
import storage from 'key-storage'; // ESM not supported
The library uses CommonJS require-style; it does not support ES module imports.
set
storage.set('key', 'value');
storage.set('key', 'value'); // correct usage shown, no common mistake
Method on the returned object.
get
storage.get('key');
Returns the value as a string.

Demonstrates basic set, get, and remove operations in a browser environment.

var storage = require('key-storage'); storage.set('theme', 'dark'); var theme = storage.get('theme'); console.log(theme); // 'dark' storage.remove('theme'); console.log(storage.get('theme')); // null
Debug
Known issues
gotchaLibrary only works in browsers; calling require in Node.js throws an error or returns undefined.
fix
Ensure code runs in a browser environment with localStorage or cookies available.
affects: >=0.0.0
gotchaThe library does not support ES module imports (e.g., import ... from 'key-storage').
fix
Use CommonJS require() or bundle with a bundler that can handle CJS.
affects: >=0.0.0
gotchaValues are stored and retrieved as strings; objects are not automatically serialized/deserialized.
fix
Manually JSON.stringify() when setting and JSON.parse() when getting objects.
affects: >=0.0.0
gotchaCookies fallback may be limited by cookie size (around 4KB) and domain/path restrictions.
fix
Be aware of cookie limitations; consider using a library with more robust fallback for large data.
affects: >=0.0.0
Errors
Common errors & fixes
ReferenceError: localStorage is not defined
Running the library in Node.js instead of a browser.
fix
Ensure the code runs in a browser environment; do not use in server-side Node.js.
TypeError: storage.set is not a function
Attempting to import the library incorrectly (e.g., using ES module import syntax).
fix
Use const storage = require('key-storage'); instead of import.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
key-storage — npm install key-storage · libregistry