ss-storage
Version:
SS Storage is library that help to store data in the session storage, or retrieve data
81 lines (54 loc) • 1.35 kB
Markdown
# SS-STORAGE
ss-storage is used:
- Read data from the local storage
- Write data to the local storage
- Delete data from the local storage
- Clear the local storage
## Usage
### Installation
```bash
npm i ss-storage --save
```
#### Data
```javascript
const data = [1, 2, 3, 4];
```
#### Import storage from 'ss-storage'
```javascript
import storage from "ss-storage";
```
##### Save to sessionstorage
```javascript
storage.set("data", data);
```
##### Read to sessionstorage
```javascript
const myData = storage.get("data");
```
```javascript
console.log(myData);
// [1, 2, 3, 4]
```
##### Delete data to sessionstorage
```javascript
storage.remove("data");
```
##### Clear sessionstorage
```javascript
storage.clear();
```
### Set method
- Sets the value of the pair identified by key to value,
- creating a new key/value pair if none existed for key previously.
```javascript
storage.set(key: string, value: any): any
```
* key ```string``` ```required```: The key identifier of data to set
* value ```any``` ```required```: The value to store
If the value is set, it will return the ```value```, else it will return ```null```
### Get method
Retrieves a value from the storage
```javascript
storage.get(key: string): any
```
Returns the current value associated with the given key, or null if the given key does not exist.