2.0.5 • Published 2 years ago

lc-storage v2.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

LC-STORAGE

lc-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

npm i lc-storage --save

Data

const data = [1, 2, 3, 4];

Import storage from 'lc-storage'

import storage from "lc-storage";
Save to localstorage
storage.set("data", data);
Read to localstorage
const myData = storage.get("data");
console.log(myData);
// [1, 2, 3, 4]
Delete data to localstorage
storage.remove("data");
Clear localstorage
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.
storage.set(key: string, value: any, setOption?: SetOption): any
storage.set(key: string, value: any, { exp?: number, nullable?: boolean }): any
  • key string required: The key identifier of data to set
  • value any required: The value to store
  • setOption object optional: Advance set configuratioon

If the value is set, it will return the value, else it will return null

interface SetOption {
  exp?: number; // Expiration time in second
  nullable?: boolean; // If the value can be null. default: false
}
// Will store [1, 2, 3, 4] in local storage with data as key.
storage.set("data", data, { exp: 60 });
// Before 60 seconds, you can get the data value
// After 60 seconds, if you call storage.get('data'), it will return null

console.log(storage.get('data')) // [1, 2, 3, 4]

setTimeout(() => {
  console.log(storage.get('data')) // null
}, 60 * 1000)

Get method

Retrieves a value from the storage

storage.get(key: string): any

Returns the current value associated with the given key, or null if the given key does not exist.

2.0.5

2 years ago

1.0.2

2 years ago

1.2.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.0.0-beta-1

2 years ago

2.0.1

2 years ago

2.0.0-beta-3

2 years ago

2.0.0

2 years ago

2.0.0-beta-2

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago