Skip to main content
Home

Built and signed on GitHub Actions

TypeScript wrapper library for the Web Storage and IndexedDB APIs

This package works with Deno, Browsers
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
a week ago (0.1.0)
class WebStorage

Browser storage manager

Constructors

new
WebStorage(storageType: StorageType)

Properties

readonly
length: number

Returns an integer representing the number of data items stored in the Storage object.

Type of browser storage this instance manages.

private
readonly
keys: Set<string>

Set of keys in the storage instance.

private
readonly
storage: Storage

Reference to the browser Storage object for this instance's StorageType.

Methods

clear(): void

Removes all keys/value pairs from the storage instance.

getItem<T>(key: string): T | null

When passed a key name, will return that key's value, or null if the key does not exist.

Returns true if a given key is present in the storage instance.

removeItem(key: string): void

Removes a key/value pair from the storage instance if it exists.

setItem(
key: string,
value: unknown,
): void

When passed a key name and value, will add that key to the storage or update that key's value if it already exists.

Static Properties

private
_local: WebStorage | null

Local storage singleton.

private
_session: WebStorage | null

Session storage singleton.

Static Methods

private
create(storageType: StorageType): WebStorage

Creates a new WebStorage instance for the given StorageType.

Gets the WebStorage instance for the StorageType.Local storage type.

Gets the WebStorage instance for the StorageType.Session storage type.

private
isAvailable(storage: Storage): boolean

Tests whether a given StorageType is available in the current context.

Tests whether StorageType.Local is available in the current environment. This determines whether self.localStorage can be used without throwing errors.

Tests whether StorageType.Session is available in the current environment. This determines whether self.sessionStorage can be used without throwing errors.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@bdavidson/browser-storage

Import symbol

import WebStorage from "@bdavidson/browser-storage/web-storage";
or

Import directly with a jsr specifier

import WebStorage from "jsr:@bdavidson/browser-storage/web-storage";