Session Storage Client
This package has the purpose of be a easy way to manage the sessionStorage from the browser considering typings and other validation.
🚀 Getting Started
These instructions will allow you to get a copy of the project running on your local machine for the purposes of Managing the Session Storage Browser with an specific package.
🔧 Installation
To install the @acctglobal/session-storage-client you must run the following command in your project:
npm i @acctglobal/session-storage-client
🖱️ Usage
in order yo use this package you can follow the example bellow
First you need to instantiate the SessionStorageClient
//Here you import the package and its functionalities
import { SessionStorageClient } from '@acctglobal/session-storage-client'
//Here you define the interface with the data for typing which SessionStorageClient will accept
interface InferfaceExample {
prop1: string
prop2: number
}
/*
* Here we create an instance of the SessionStorageClient sending the interface as class typing
* and, as parameter, the name of the sessionStorage item you want to deal with;.
*/
const sessionStorageExample = new SessionStorageClient<InferfaceExample>('example')
/*
* It is possible to create other instances of SessionStorageClient with different typings
* and attach them with other variables
*/
Here it is the main functions being used
/*
* "setProperty" - This function sets the value of a property in the sessionStorage
* according to the key defined when we instantiate the SessionStorageClient.
* It is important paying attention to the function parameters,
* because the first must be a property of the previouly defined interface
* and the second must be a type of the property.
*/
sessionStorageExample.setProperty('prop1', 'this is an example')
sessionStorageExample.setProperty('prop2', 2)
/*
* "getProperty" - This function gets the data from sessionStorage
* through the sessionStorageClient.
* The parameter must be a property of the interface type defined
* when instantiating the SessionStorageClient
* In this case, the parameters could only be "prop1" or "prop2".
*/
const variable = sessionStorageExample.getProperty('prop1')
//returns 'this is an example' (setted previously)
/*
* "resetStorage" - This function resets the item in the sessionStorage Browser
* and in the instance of the SessionStorageClient.
*/
sessionStorageExample.resetStorage()
Parameters
Param name | Type | Description | Default value |
---|
sessionStorageKey | string | Defines the item in the browser sessionStorage that will be read and changed. | none |
resetStorage | boolean | Defines whether the current sessionStorage item in the browser will be reseted. | false |
isReadonly | boolean | Defines whether the instance of the SessionStorageClient will be able to change the sessionStorage item in the browser or not. | false |
🛠️ Built with
Mention the tools you used to create your project
📌 Versioning
We use SemVer for version control. For available versions, note the tags in this repository.
✒️ Authors
Mention all those who helped lift the project from its inception
⌨️ By João Castro 😊