百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

stokado

> 前端框架
开源

具有丰富功能的代理包装器,用于浏览器存储,支持序列化、反应性、过期和一次性值。可与 localStorage、sessionStorage 和 asy 等对象一起使用

386 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

具有丰富功能的代理包装器,用于浏览器存储,支持序列化、反应性、过期和一次性值。可与 localStorage、sessionStorage 和 asy 等对象一起使用

…

shell npm install stokado


### Proxy

```js
import { createProxyStorage } from 'stokado'

const storage = createProxyStorage(localStorage)

storage.getItem('test')

…

js
const storage = createProxyStorage(localStorage)

storage.test = 'hello stokado'

storage.test // 'hello stokado'

delete storage.test

The storage also have the same methods and properties: key(), getItem(), setItem(), removeItem(), clear() and length.

2. Serializer

Keep the type of storage value unchanged

javascript
// number
storage.test = 0
storage.test === 0

// boolean
storage.test = false
storage.test === false

// undefined
storage.test = undefined
storage.test === undefined

// null
storage.test = null
storage.test === null

// object
storage.test = { hello: 'world' }
storage.test.hello === 'stokado'

// array
storage.test = ['hello']
storage.test.push('stokado')
storage.test.length // 2

// Date
storage.test = new Date('2000-01-01T00:00:00.000Z')
storage.test.getTime() === 946684800000

// RegExp
storage.test = /d(b+)d/g
storage.test.test('cdbbdbsbz')

// function
storage.test = function () {
  return 'hello stokado!'
}
storage.test() === 'hello stokado!'

3. Subscribe

Subscribe to value changes

javascript
storage.on(key, callback)

storage.once(key, callback)

storage.off([[key], callback])
  • key: the name of the item to subscribe to. Support obj.a for Object and list[0] for Array, and also Array length.
  • callback: the function to call when the item is changed. Includes newValue and oldValue.

Tips: For off, if a callback exists, it removes the trigger of the specified callback; otherwise, it removes all callbacks bound to the key; if the key is empty, it removes all listening callbacks.

4. Expired

Set expires for items

javascript
storage.setExpires(key, expires)

storage.getExpires(key)

storage.removeExpires(key)
  • key: the name of the item to set expires.
  • expires: accept string、number and Date.

5. Disposable

Get the value once, which can be used for communication through storage.

javascript
storage.setDisposable(key)
  • key:the name of the item to set disposable.

6. Options

Get expires and disposable configuration information for the specified item

javascript
storage.getOptions(key)

Set expires and disposable using setItem

javascript
storage.setItem(key, value, { expires, disposable })

7. Quota Alert

Monitor storage usage and get notified when approaching limits

javascript
import { createProxyStorage, MB } from 'stokado'

const storage = createProxyStorage(localStorage, {
  quota: 5 * MB,
  onQuotaExceeded({ current, limit, key }) {
    console.warn(`Storage quota exceeded: ${current}/${limit} bytes, key: "${key}"`)
    return false
  }
})

storage.getUsage()

await storage.ready

…

js
import { createProxyStorage } from 'stokado'
import { cookieStorage } from 'stokado/presets/cookie'

const storage = createProxyStorage(cookieStorage)

WeChat Mini Program

javascript
import { createProxyStorage } from 'stokado'
import { wechatStorage } from 'stokado/presets/wechat'

const storage = createProxyStorage(wechatStorage)

Async version:

javascript
import { wechatStorageAsync } from 'stokado/presets/wechat'

const storage = createProxyStorage(wechatStorageAsync)

Douyin Mini Program

javascript
import { douyinStorage, douyinStorageAsync } from 'stokado/presets/douyin'

Alipay Mini Program

javascript
import { alipayStorage, alipayStorageAsync } from 'stokado/presets/alipay'

uni-app

javascript
import { uniStorage, uniStorageAsync } from 'stokado/presets/uni-app'

React Native

React Native requires injecting the AsyncStorage instance:

javascript
import AsyncStorage from '@react-native-async-storage/async-storage'
import { createProxyStorage } from 'stokado'
import { createReactNativeStorage } from 'stokado/presets/react-native'

const storage = createProxyStorage(createReactNativeStorage(AsyncStorage))

Node.js

javascript
import { createProxyStorage } from 'stokado'
import { memoryStorage } from 'stokado/presets/node'

const storage = createProxyStorage(memoryStorage)

Work with localForage

localForage provides the same API as localStorage, it can be used in conjunction with stokado.

javascript
import localForage from 'localforage'
import { createProxyStorage } from 'stokado'

const local = createProxyStorage(localForage, { channel: 'localForage' })

However, localForage uses an async API, it needs to be called using Promise.

javascript
await (local.test = 'hello localForage')

// or

await local.setItem('test', 'hello localForage')

Multiple instances

You can create multiple instances of localForage that point to different stores using createInstance.

javascript
const store = localforage.createInstance({
  name: 'nameHere'
})
const proxyStore = createProxyStorage(store, { channel: 'store' })

const otherStore = localforage.createInstance({
  name: 'otherName'
})
const proxyOtherStore = createProxyStorage(otherStore, { channel: 'otherStore' })

Keywords

stokado is a localStorage wrapper, browser storage proxy, web storage library, and storage utility for JavaScript. It provides localStorage serialization, storage reactivity, storage subscription, storage expiration, storage quota alert, cross-tab storage sync, and async storage support. Alternatives to store2, store.js, lscache, localForage, and idb-keyval. Works with localStorage, sessionStorage, localForage, and any storage-like object.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptbroadcastchannelbrowser-storagecacheexpiration

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架