A lightweight wrapper for W3C Storage API (localStorage, sessionStorage, globalStorage) with JSON serialization, namespace support, and optional stringify control. Version 2.1.2 provides a stable API for browser and Node.js environments. Key differentiators: simple abstraction with namespace isolation, compatibility with various DOMStorage implementations, and configurable stringification to avoid double encoding. The library has low activity and known gotchas around undefined/null handling.
npm install json-storageNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage with Node.js: create a namespaced store, set/get/remove JSON values, and avoid double stringification.
Use `null` instead of `undefined` to represent 'no value'.
Use `store.has(key)` or `store.keys()` to check existence if needed.
Be explicit: store `'"null"'` if you need the string. Avoid relying on round-tripping of the string "null" as a top-level value.
Install via npm: `npm install json-storage` and bundle with your preferred tool (webpack, browserify, etc.).
Add `const localStorage = require('localStorage');` at the top of your script.Use `const { JsonStorage } = require('json-storage');` in CommonJS or `import { JsonStorage } from 'json-storage';` in ES modules.Run `npm install localStorage` (only needed for Node.js; browsers provide it natively).