Registry / storage / can-zone-storage

can-zone-storage

JSON →
library1.0.1jsnpmunverified

Zone-safe memory-based storage for CanJS applications, version 1.0.1 (latest stable, no major updates). Designed for compatibility with Done-SSR (Server Side Rendering) to isolate state per zone. Lightweight, zero-dependency, part of the CanJS ecosystem. Differentiates from global storage by scoping data to asynchronous zones, preventing cross-request leaks.

npm install can-zone-storage
INSTALL
IMPORT
SIG · CAN-ZONE-STORAGE
C
can-zone-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
import canZoneStorage from 'can-zone-storage'
import * as canZoneStorage from 'can-zone-storage'
Package exports a single default function. Common mistake is named import.
ZoneStorage
import ZoneStorage from 'can-zone-storage'
import { ZoneStorage } from 'can-zone-storage'
The export is a default function (though class-like). Named import will result in undefined.
require
const canZoneStorage = require('can-zone-storage')
const { default: canZoneStorage } = require('can-zone-storage')
CommonJS uses default require, no destructuring needed.
can-zone-storage (ESM in Node)
const storage = (await import('can-zone-storage')).default
const storage = await import('can-zone-storage')
Dynamic import yields module object; need .default to access the default export.

Creates a zone-isolated storage instance, demonstrates set/get/remove/clear operations.

import canZoneStorage from 'can-zone-storage'; // Create a zone-safe storage instance const storage = canZoneStorage(); // Set and get values within the zone storage.setItem('key', 'value'); console.log(storage.getItem('key')); // 'value' // Remove an item storage.removeItem('key'); // Clear all items storage.clear(); // Works with CanJS zones (e.g., with can-zone) // Each zone gets isolated storage, preventing cross-request data leaks
Debug
Known issues
gotchaStorage instances are not shared across zones. If you need persistent data outside zones, use a different storage mechanism.
fix
Use a global or explicit shared storage if cross-zone persistence is needed.
affects: >=1.0.0
gotchaThe storage API mimics localStorage but is synchronous and in-memory. Do not use for large data or persistent storage.
fix
Consider IndexedDB or other persistent solutions for large/long-lived data.
affects: >=1.0.0
gotchaSetting or getting items outside a running zone may cause unexpected behavior or errors. Ensure you are within a zone context (e.g., CanJS zone).
fix
Wrap code in a zone using can-zone before using can-zone-storage.
affects: >=1.0.0
deprecatedNo deprecation warnings exist; package is maintained but not actively updated. API stable.
fix
No action needed; consider checking for newer versions or alternatives if issues arise.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , _canZoneStorage.default) is not a function
Using named import destructuring with Babel or TypeScript expecting a default export.
fix
Use default import syntax: import canZoneStorage from 'can-zone-storage'
Module not found: Can't resolve 'can-zone-storage'
Missing package install or incorrect import path.
fix
Run `npm install can-zone-storage` (v1.0.1) and ensure import is from 'can-zone-storage'.
Cannot read property 'setItem' of undefined
Calling methods on the module itself instead of an instance created by calling the default export.
fix
Create an instance: const storage = canZoneStorage(); then use storage.setItem().
ReferenceError: zone is not defined
Using can-zone-storage without a proper zone context (e.g., missing can-zone setup).
fix
Wrap your code in a zone: require('can-zone').create().run(() => { ... });
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
can-zone-storage — npm install can-zone-storage · libregistry