keyv-browser
2
总安装量
2
周安装量
#68505
全站排名
安装命令
npx skills add https://github.com/zaaack/prompts --skill keyv-browser
Agent 安装分布
amp
2
gemini-cli
2
github-copilot
2
codex
2
kimi-cli
2
opencode
2
Skill 文档
keyv-browser
keyv-browser provides two specialized storage adapters that allow the standard Keyv API to work seamlessly within a web browser environment.
Available Adapters
| Adapter | Storage Engine | Best For |
|---|---|---|
KeyvLocalStorage |
window.localStorage |
Simple, synchronous, small strings (<5MB). |
KeyvIndexedDB |
IndexedDB |
Larger datasets, binary data, and non-blocking I/O. |
Usage Patterns
1. Standard Keyv Integration
You can swap the storage engine based on your persistence needs without changing your application logic.
import Keyv from 'keyv'
import { KeyvLocalStorage, KeyvIndexedDB } from 'keyv-browser'
// For simple settings
const settingsStore = new Keyv({
store: new KeyvLocalStorage()
});
// For heavy data/caching
const cacheStore = new Keyv({
store: new KeyvIndexedDB()
});
2. Declarative “Field” Usage
Use makeField to create direct, type-safe accessors for specific keys.
import { KeyvLocalStorage, makeField } from 'keyv-browser'
class AppStore extends KeyvLocalStorage {
// makeField(store, key, defaultValue)
theme = makeField(this, 'ui_theme', 'light')
sessionCount = makeField(this, 'session_count', 0)
}
const store = new AppStore()
// Note: keyv-browser operations are asynchronous
await store.theme.set('dark')
const currentTheme = await store.theme.get() // 'dark'