Session Storage Client
This package offers a typed abstraction layer for interacting with the browser's sessionStorage
through a generically typed TypeScript class, SessionStorageClient.
🔧 Installation
npm i @acctglobal/session-storage-client
🖱️ Usage
import { SessionStorageClient } from '@acctglobal/session-storage-client';
interface ExampleInterface {
prop1: string;
prop2: number;
}
const exampleClient = new SessionStorageClient<ExampleInterface>('exampleKey');
The exampleClient
variable now has a couple of things going for you:
exampleClient.setProperty('prop1', 'this is an example');
exampleClient.setProperty('prop2', 2);
exampleClient.setProperty('prop3', 2);
exampleClient.setProperty('prop1', 42);
const prop1 = exampleClient.getProperty('prop1');
let obj = {
prop1: 'this is a string',
prop2: 12
} as ExampleInterface;
exampleClient.setFullObject(obj);
const fullObject = exampleClient.getFullObject();
exampleClient.resetStorage();
window.addEventListener('exampleKey', function () {
});
✒️ Authors