Registry / storage / nittro-extras-storage

nittro-extras-storage

JSON →
library2.0.2jsnpmunverified

Nittro/Storage is a client-side storage abstraction library for web applications, part of the Nittro framework. Version 2.0.2 provides a unified API for localStorage, sessionStorage, and custom storage backends with automatic JSON serialization and expiration support. It uses ES modules and TypeScript definitions. Compared to raw Web Storage API, it adds type safety (when used with TypeScript), fallback mechanisms for private browsing, and a consistent interface across storage types. The package is passively maintained with no recent updates; it depends on the Nittro DI container

npm install nittro-extras-storage
INSTALL
IMPORT
SIG · NITTRO-EXTRAS-STOR
N
nittro-extras-storage
storagejavascriptv2.0.2
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.

Storage
import { Storage } from 'nittro-extras-storage'
Default export is not available; use named import.
LocalStorage
import { LocalStorage } from 'nittro-extras-storage'
Creates a Storage instance bound to localStorage.
SessionStorage
import { SessionStorage } from 'nittro-extras-storage'
Creates a Storage instance bound to sessionStorage.

Demonstrates creating LocalStorage and SessionStorage instances with prefix, CRUD operations, and custom backend usage.

import { Storage, LocalStorage, SessionStorage } from 'nittro-extras-storage'; // Create a LocalStorage instance const local = LocalStorage.create('myapp'); // Set a value local.setItem('user', { name: 'Alice', age: 30 }); // Get a value (auto-deserialized) const user = local.getItem('user'); console.log(user.name); // "Alice" // Remove an item local.removeItem('user'); // Clear all items with prefix local.clear(); // Session storage example const session = SessionStorage.create('myapp'); session.setItem('token', 'abc123'); // Custom storage backend import { StorageEngine } from 'nittro-extras-storage'; const customEngine = new StorageEngine({ name: 'custom', type: 'localStorage' }); const storage = new Storage(customEngine, 'myapp'); storage.setItem('key', 'value');
Debug
Known issues
gotchaThe package uses prefix-based storage keys under the hood. All keys are prefixed with the namespace provided during creation (e.g., 'myapp::user'). This is transparent but can cause conflicts if you manually access raw localStorage outside the library.
fix
Always use the provided Storage methods instead of direct localStorage access for prefixed keys.
affects: all
gotchaExpiration support is optional and not enabled by default. To use expiring items, you must configure the storage with a TTL function or use setItemWithExpiration.
fix
Use LocalStorage.createWithExpiration(options) or set the expiration parameter individually.
affects: >=1.0
breakingVersion 2.0.0 moved to ES modules only; CommonJS require() is no longer supported. Using require() will result in an error.
fix
Use ES module imports (import { ... } from 'nittro-extras-storage') or enable ESM in your project.
affects: >=2.0
deprecatedThe method setWithExpiration has been deprecated in favor of setItemWithExpiration in version 2.0.0.
fix
Use setItemWithExpiration(key, value, ttl) instead.
affects: >=2.0
gotchaSessionStorage.create() may not work in environments where sessionStorage is blocked (e.g., some private browsing modes). The library attempts to detect this but may fail.
fix
Wrap creation in a try-catch or check for availability using Storage.isSupported() before usage.
affects: all
gotchaStored values are serialized as JSON. Objects and arrays work, but functions, Symbols, and undefined will be lost or cause errors.
fix
Only store JSON-serializable values (strings, numbers, booleans, plain objects, arrays).
affects: all
Errors
Common errors & fixes
Could not resolve dependency 'localStorage' in 'storage.js'
The import path assumes a Node.js environment but is used in browser; the package relies on global localStorage.
fix
Ensure the package runs in a browser environment where localStorage is globally available. For Node.js, use a polyfill.
Uncaught TypeError: Storage is not a constructor
Incorrect import style: import Storage from '...' (default import) instead of named import.
fix
Use import { Storage } from 'nittro-extras-storage'.
Cannot find module 'nittro-extras-storage'
Package not installed; or using pnpm with a different registry path.
fix
Run npm install nittro-extras-storage. If using pnpm, ensure your .npmrc is correct.
TypeError: Illegal invocation
Trying to pass the storage's method as a callback without binding the context.
fix
Bind the method: const getItem = storage.getItem.bind(storage); or use arrow function: (key) => storage.getItem(key).
TypeError: storage.setItem is not a function
The Storage instance was not created correctly; maybe using Storage class directly without underlying engine.
fix
Create storage via LocalStorage.create() or SessionStorage.create().
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
22
Amazon
1
Resources
nittro-extras-storage — npm install nittro-extras-storage · libregistry