WebStorageService

Type-safe wrapper for localStorage and sessionStorage with JSON serialization, optional key prefixing, and reactive change detection via Observables.

TypeScriptexample.ts
import { WebStorageService } from '@angular-helpers/browser-web-apis'

# Methods

MethodSignatureReturnsDescription
isSupportedisSupported(): booleanbooleanReturns true if either local or session storage is usable.
getStorageEventsgetStorageEvents(): Observable<StorageEvent>Observable<StorageEvent>Stream of every storage mutation observed in this tab or other tabs.
setLocalStoragesetLocalStorage(key: string, value: T, options: StorageOptions): booleanbooleanPublic method setLocalStorage.
getLocalStoragegetLocalStorage(key: string, defaultValue: T | null, options: StorageOptions): T | nullT | nullPublic method getLocalStorage.
removeLocalStorageremoveLocalStorage(key: string, options: StorageOptions): booleanbooleanPublic method removeLocalStorage.
clearLocalStorageclearLocalStorage(options: StorageOptions): booleanbooleanPublic method clearLocalStorage.
setSessionStoragesetSessionStorage(key: string, value: T, options: StorageOptions): booleanbooleanPublic method setSessionStorage.
getSessionStoragegetSessionStorage(key: string, defaultValue: T | null, options: StorageOptions): T | nullT | nullPublic method getSessionStorage.
removeSessionStorageremoveSessionStorage(key: string, options: StorageOptions): booleanbooleanPublic method removeSessionStorage.
clearSessionStorageclearSessionStorage(options: StorageOptions): booleanbooleanPublic method clearSessionStorage.
getLocalStorageSizegetLocalStorageSize(options: StorageOptions): numbernumberPublic method getLocalStorageSize.
getSessionStorageSizegetSessionStorageSize(options: StorageOptions): numbernumberPublic method getSessionStorageSize.
watchLocalStoragewatchLocalStorage(key: string, options: StorageOptions): Observable<T | null>Observable<T | null>Public method watchLocalStorage.
watchSessionStoragewatchSessionStorage(key: string, options: StorageOptions): Observable<T | null>Observable<T | null>Public method watchSessionStorage.
getNativeLocalStoragegetNativeLocalStorage(): StorageStoragePublic method getNativeLocalStorage.
getNativeSessionStoragegetNativeSessionStorage(): StorageStoragePublic method getNativeSessionStorage.
LCP N/A
CLS N/A
INP N/A