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
| Method | Signature | Returns | Description |
|---|---|---|---|
isSupported | isSupported(): boolean | boolean | Returns true if either local or session storage is usable. |
getStorageEvents | getStorageEvents(): Observable<StorageEvent> | Observable<StorageEvent> | Stream of every storage mutation observed in this tab or other tabs. |
setLocalStorage | setLocalStorage(key: string, value: T, options: StorageOptions): boolean | boolean | Public method setLocalStorage. |
getLocalStorage | getLocalStorage(key: string, defaultValue: T | null, options: StorageOptions): T | null | T | null | Public method getLocalStorage. |
removeLocalStorage | removeLocalStorage(key: string, options: StorageOptions): boolean | boolean | Public method removeLocalStorage. |
clearLocalStorage | clearLocalStorage(options: StorageOptions): boolean | boolean | Public method clearLocalStorage. |
setSessionStorage | setSessionStorage(key: string, value: T, options: StorageOptions): boolean | boolean | Public method setSessionStorage. |
getSessionStorage | getSessionStorage(key: string, defaultValue: T | null, options: StorageOptions): T | null | T | null | Public method getSessionStorage. |
removeSessionStorage | removeSessionStorage(key: string, options: StorageOptions): boolean | boolean | Public method removeSessionStorage. |
clearSessionStorage | clearSessionStorage(options: StorageOptions): boolean | boolean | Public method clearSessionStorage. |
getLocalStorageSize | getLocalStorageSize(options: StorageOptions): number | number | Public method getLocalStorageSize. |
getSessionStorageSize | getSessionStorageSize(options: StorageOptions): number | number | Public method getSessionStorageSize. |
watchLocalStorage | watchLocalStorage(key: string, options: StorageOptions): Observable<T | null> | Observable<T | null> | Public method watchLocalStorage. |
watchSessionStorage | watchSessionStorage(key: string, options: StorageOptions): Observable<T | null> | Observable<T | null> | Public method watchSessionStorage. |
getNativeLocalStorage | getNativeLocalStorage(): Storage | Storage | Public method getNativeLocalStorage. |
getNativeSessionStorage | getNativeSessionStorage(): Storage | Storage | Public method getNativeSessionStorage. |