Registry / storage / storage-available

storage-available

JSON →
library1.1.0jsnpmunverified

Detects whether web storage (localStorage or sessionStorage) is available and functional in the browser. Version 1.1.0 is the current stable release, with infrequent updates. It implements the feature detection algorithm recommended by MDN, handling edge cases like Safari private browsing where storage exists but throws on writes. Ships TypeScript definitions. Minimal zero-dependency package.

npm install storage-available
INSTALL
IMPORT
SIG · STORAGE-AVAILABLE
S
storage-available
storagejavascriptv1.1.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.

storageAvailable
import storageAvailable from 'storage-available'
const { storageAvailable } = require('storage-available')
Default export only; named import will fail. CJS require works.
storageAvailable
const storageAvailable = require('storage-available')
const sa = require('storage-available').storageAvailable
CommonJS require returns the function directly.
typeof storageAvailable
import type { default as StorageAvailableType } from 'storage-available'
import { storageAvailable } from 'storage-available'
TypeScript: use default import pattern for types.

Detect availability of localStorage and sessionStorage with recommended MDN method.

import storageAvailable from 'storage-available'; if (storageAvailable('localStorage')) { console.log('localStorage is available'); localStorage.setItem('test', 'value'); } else { console.log('localStorage is not available, consider fallback'); } // sessionStorage detection works similarly if (storageAvailable('sessionStorage')) { console.log('sessionStorage is available'); }
Debug
Known issues
gotchaThis module detects the 'storage' API, not side effects like quota limits. A true result doesn't guarantee writes will succeed.
fix
Wrap storage writes in try/catch as backup.
affects: all
deprecatedThe module's function signature expects a string literal 'localStorage' or 'sessionStorage'. Passing other values returns false without warning.
fix
Only call with 'localStorage' or 'sessionStorage'.
affects: all
gotchaIn older Safari private browsing mode (iOS <11), the function returns false due to the detection algorithm used.
fix
Consider using a try/catch write test as a more comprehensive check on older iOS.
affects: all
gotchaRequires a browser environment; will throw if imported in Node.js without a Web Storage implementation.
fix
Only import in browser bundles or provide a polyfill for Node.js tests.
affects: all
gotchaTypeScript type definitions are present but the default export type is 'unknown'. Users may need to assert types manually.
fix
Use `as (storage: 'localStorage' | 'sessionStorage') => boolean` or create a local type.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: storageAvailable is not a function
Using named import instead of default import in ESM.
fix
Replace `import { storageAvailable }` with `import storageAvailable`
ReferenceError: localStorage is not defined
Running code in Node.js environment without a Web Storage shim.
fix
Only call storageAvailable in browser context or provide polyfills for testing.
TypeError: storageAvailable is not a function (in React Native or Web Workers)
Environment may not have `globalThis` or `window` as expected.
fix
Check if storageAvailable exists before calling, or use a try/catch.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
26
Amazon
1
OpenAI (training)
1
Resources
storage-available — npm install storage-available · libregistry