Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pcrab/pblive-cli
https://github.com/pcrab/pblive-cli
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/pcrab/pblive-cli
- Owner: Pcrab
- License: mit
- Created: 2022-09-24T15:03:11.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T10:11:09.000Z (about 1 year ago)
- Last Synced: 2024-11-07T01:28:55.472Z (about 2 months ago)
- Language: TypeScript
- Size: 498 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pls-storage
A simple typescript library to enhance browser local/session storage.
## Usage
`pls-storage` provides two storages: `lstorage` for `localStorage`, and `sstorage` for `sessionStorage`.
Value can be any primitive type, or object that contains primitive types.
Functions can be stored due to the implementation of custom storage, but after reloading the page, all the functions will be lost.
```typescript
import { lstorage } from "pls-storage";/**
* "$PLS_STORAGE_testKey1": '{"value":"testStringValue"}'
*/
lstorage.setItem("testKey1", "testStringValue");
lstorage.getItem("testKey1") // "testStringValue"/**
* "$PLS_STORAGE_testKey2": '{"value":{"someValue1":123,"someValue2":"123"}}'
*/
lstorage.setItem("testKey2", {
someValue1: 123,
someValue2: "123"
});
lstorage.getItem("testKey2") // {someValue1: 123, someValue2: "123"}
````pls-storage` supports `readOnly` and `expiresAt` options.
``` typescript
import { lstorage } from "pls-storage";/**
* "$PLS_STORAGE_testKey3": '{"value":"testStringValue","expiresAt":"2022-09-19T09:11:48.367Z"}'
*/
lstorage.setItem("testKey1", "testStringValue", {
// new Date().toJSON();
expiresAt: new Date('2022-09-19T09:11:48.367Z')
});
lstorage.getItem("testKey1") // undefined/**
* "$PLS_STORAGE_testKey3": '{"value":"testStringValue","readOnly":true}'
*/
lstorage.setItem("testKey2", "testStringValue", {
readOnly: true
});
lstorage.setItem("testKey2", "changedValue");
lstorage.getItem("testKey2") // "testStringValue"
```