UNPKG

@lonewolfspace/storage-manager-ts

Version:

A universal browser storage manager with optional AES encryption support for localStorage, sessionStorage, and cookies.

53 lines (52 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClientSessionStorageManager = void 0; const base_storage_manager_1 = require("./base-storage-manager"); class ClientSessionStorageManager extends base_storage_manager_1.BaseStorageManager { /** * Set a value in session storage * @param key The storage key * @param value The value to store */ static setItem(key, value) { if (typeof window === "undefined") { throw new Error("This method can only be used in client components"); } const encryptedValue = this.encryptValue(value); sessionStorage.setItem(key, encryptedValue); } /** * Get a value from session storage * @param key The storage key * @returns The stored value or undefined if not found */ static getItem(key) { if (typeof window === "undefined") { throw new Error("This method can only be used in client components"); } const encryptedValue = sessionStorage.getItem(key); if (!encryptedValue) return undefined; return this.decryptValue(encryptedValue); } /** * Remove a value from session storage * @param key The storage key */ static removeItem(key) { if (typeof window === "undefined") { throw new Error("This method can only be used in client components"); } sessionStorage.removeItem(key); } /** * Clear all items from session storage */ static clear() { if (typeof window === "undefined") { throw new Error("This method can only be used in client components"); } sessionStorage.clear(); } } exports.ClientSessionStorageManager = ClientSessionStorageManager;