Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/holyhigh2/mystores
A unified web storage interface for localStorage/sessionStorage/cookie/indexDB/...
https://github.com/holyhigh2/mystores
Last synced: 8 days ago
JSON representation
A unified web storage interface for localStorage/sessionStorage/cookie/indexDB/...
- Host: GitHub
- URL: https://github.com/holyhigh2/mystores
- Owner: holyhigh2
- License: mit
- Created: 2023-05-21T11:31:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-28T10:35:31.000Z (11 months ago)
- Last Synced: 2024-12-03T05:45:12.867Z (25 days ago)
- Language: JavaScript
- Size: 49.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# MyStores
![npm](https://img.shields.io/npm/v/mystores)
![NPM](https://img.shields.io/npm/l/mystores)A unified key-value web storage interface for localStorage/sessionStorage/cookie/indexedDB/...
## Features
- Unified store APIs
- Multi-storage
- Value (un)serialize support
- Expires setting support## Install
```
npm i mystores
```## Usage
```js
//1. Write store
myss.set('a',{a:1})
myss.set('b',/123/)
myss.set('c',new Date())
myss.set('d',-123)
myss.set('e',null)
myss.set('f',Infinity)
myss.set('blob',new window.Blob(...))// for indexed only//2. Read store
myss.get('a')//get Object
myss.get('b')//get RegExp
myss.get('c')//get Date
myss.get('blob')//get blob//3. Get all keys
myss.keys()//4. Multi instance
const Cookie = myss.getStore('cookie')
const InDB = myss.getStore('indexed')Cookie.set('a',{a:1})
Cookie.set('b',/123/)
Cookie.set('c',new Date())
InDB.set('d',-123)
InDB.set('e',null)
InDB.set('f',Infinity)
```## API
```ts
import myss,{StoreType} from 'mystores'//Set store type. Default 'local'
myss.options({
type:StoreType.COOKIE
})//The 'options' is only supported when storeType is set to 'cookie'
myss.set(key:string,value:any,expires?:number,options?:{path:string,domain?:string,secure:boolean}):boolean | Promise//Get store
myss.get(key: string):any|Promise//The return value will always be 'null' when storeType is set to 'indexed'
myss.getString(key: string):string | nullmyss.remove(key:string):boolean | Promise
myss.has(key:string):boolean | Promise
//Get all keys
myss.keys():string[] | Promise//Clear all
myss.clear()
```
*** All return values of functions will be changed to Promise when storeType is set to 'indexed' ***## Demo
见test/index.spec.ts