https://github.com/bytebodger/session-storage-is-available
A simple utility function to safely determine whether sessionStorage is available in the current environment
https://github.com/bytebodger/session-storage-is-available
Last synced: 5 months ago
JSON representation
A simple utility function to safely determine whether sessionStorage is available in the current environment
- Host: GitHub
- URL: https://github.com/bytebodger/session-storage-is-available
- Owner: bytebodger
- License: mit
- Created: 2021-03-19T01:39:49.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-16T15:00:59.000Z (over 4 years ago)
- Last Synced: 2025-09-24T00:52:02.446Z (9 months ago)
- Language: JavaScript
- Size: 78.1 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# session-storage-is-available
`session-storage-is-available` is a tiny utility function to safely determine whether sessionStorage is available in the current environment. It's dangerous to _assume_ that `sessionStorage()` is available. It can be absent in non-supported browsers, or when scripts are invoked from the command line, or when the user's browser is in Incognito Mode. Trying to access `sessionStorage()` when it's unavailable can spawn an `Error`. So it's best to test for its existence before attempting to access it.
## Usage
After installation, import the package:
```javascript
import { sessionStorageIsAvailable } from '@toolz/session-storage-is-available';
```
### sessionStorageIsAvailable()
`sessionStorageIsAvailable()` attempts to set-and-remove a value in `sessionStorage`, returning a Boolean value based on its failure or success.
```javascript
const API = {
arguments: {
// none
},
returns: Boolean,
}
```
**Examples:**
```javascript
sessionStorageIsAvailable(); // returns Boolean TRUE in "normal" browser situations
sessionStorageIsAvailable(); // returns Boolean FALSE when invoked outside a "normal" browser
// or when the browser can sessionStorage disabled (e.g., Incognito Mode)
```