
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A type-safe, extensible storage library with unified API supporting Memory, LocalStorage, SessionStorage, and IndexedDB
一个类型安全、可扩展的存储库,提供统一的存储接口,支持多种存储方式。
# 使用 pnpm(推荐)
pnpm add store-vert
# 使用 npm
npm install store-vert
# 使用 yarn
yarn add store-vert
import { createStore, STORAGE_KEYS } from 'store-vert'
// 定义存储的数据结构
type UserSchema = {
name: string
age: number
email: string
}
// 创建存储实例(使用内存存储)
const storage = createStore<UserSchema>(STORAGE_KEYS.memory)
// 设置值
storage.setItem('name', 'John')
storage.setItem('age', 25)
storage.setItem('email', 'john@example.com')
// 获取值
const name = storage.getItem('name') // 'John'
const age = storage.getItem('age') // 25
// 删除值
storage.removeItem('name')
// 清空所有数据
storage.clear()
// 获取存储项数量
const count = storage.length()
// 获取所有键
const keys = storage.keys()
// 迭代所有项
storage.iterate((value, key, index) => {
console.log(key, value, index)
})
import { createStore, STORAGE_KEYS } from 'store-vert'
type AppSchema = {
theme: 'light' | 'dark'
language: string
}
// 使用 localStorage
const localStore = createStore<AppSchema>(STORAGE_KEYS.local)
// 使用 sessionStorage
const sessionStore = createStore<AppSchema>(STORAGE_KEYS.session)
// 使用 IndexedDB
const indexedDBStore = createStore<AppSchema>(STORAGE_KEYS.indexeddb)
// 使用内存存储(不持久化)
const memoryStore = createStore<AppSchema>(STORAGE_KEYS.memory)
import { createStore, STORAGE_KEYS } from 'store-vert'
type ComplexSchema = {
user: {
id: number
name: string
profile: {
avatar: string
bio: string
}
}
settings: {
theme: string
notifications: boolean
}
}
const storage = createStore<ComplexSchema>(STORAGE_KEYS.local)
// 存储复杂对象
storage.setItem('user', {
id: 1,
name: 'John',
profile: {
avatar: 'https://example.com/avatar.jpg',
bio: 'Developer'
}
})
// 获取时会自动反序列化
const user = storage.getItem('user')
创建存储实例的工厂函数。
function createStore<Schema extends AnyRecord, K extends keyof ExtendStoreMap>(
key: K,
...args: InjectStoreParameters<K>
): ExtendStoreMap<Schema>[K]
参数:
key: 存储类型键(STORAGE_KEYS.memory | STORAGE_KEYS.local | STORAGE_KEYS.session | STORAGE_KEYS.indexeddb)args: 可选的存储初始化参数返回: 增强的存储实例
所有存储实例都实现了统一的接口:
设置存储项。
setItem<K extends keyof Schema>(key: K, value: Schema[K]): Schema[K]
获取存储项。
getItem<K extends keyof Schema>(key: K): Schema[K] | undefined
删除存储项。
removeItem<K extends keyof Schema>(key: K): void
清空所有存储项。
clear(): void
获取存储项数量。
length(): number
获取所有键的数组。
keys(): Array<keyof Schema>
迭代所有存储项。
iterate(
callback: (value: Schema[keyof Schema], key: keyof Schema, index: number) => void
): void
内存存储,数据仅存在于内存中,页面刷新后丢失。
const storage = createStore<Schema>(STORAGE_KEYS.memory)
特点:
浏览器本地存储,数据持久化到本地。
const storage = createStore<Schema>(STORAGE_KEYS.local)
特点:
会话存储,数据仅在当前标签页有效。
const storage = createStore<Schema>(STORAGE_KEYS.session)
特点:
浏览器索引数据库,适合存储大量结构化数据。
const storage = createStore<Schema>(STORAGE_KEYS.indexeddb)
特点:
你可以通过注册表模式添加自定义存储类型:
import { inject, createStore } from 'store-vert'
import type { Store, AnyRecord } from 'store-vert'
// 定义自定义存储类
class CustomStore<Schema extends AnyRecord = AnyRecord> implements Store<Schema> {
// 实现 Store 接口的所有方法
getItem(key: keyof Schema): Schema[keyof Schema] | undefined {
// 实现逻辑
}
// ... 其他方法
}
// 注册自定义存储
inject(CustomStore, 'custom')
// 使用自定义存储
const storage = createStore<Schema>('custom')
# 克隆仓库
git clone <repository-url>
cd store-vert
# 安装依赖
pnpm install
# 运行测试
pnpm test
# 运行测试(监听模式)
pnpm test:watch
# 运行测试(带覆盖率)
pnpm test:coverage
# 代码检查
pnpm lint
# 代码格式化
pnpm format
# 构建
pnpm build
# 类型检查
pnpm typecheck
store-vert/
├── src/ # 源代码
│ ├── modules/ # 存储模块实现
│ │ ├── memory/ # 内存存储
│ │ ├── local/ # localStorage
│ │ ├── session/ # sessionStorage
│ │ └── indexeddb/ # IndexedDB
│ ├── types/ # 类型定义
│ ├── utils/ # 工具函数
│ ├── constants/ # 常量定义
│ ├── registry.ts # 注册表
│ ├── createStore.ts # 工厂函数
│ └── index.ts # 入口文件
├── tests/ # 测试文件
├── dist/ # 构建输出
└── docs/ # 文档
构建后会生成以下文件:
dist/index.js - CommonJS 格式dist/index.esm.js - ES Module 格式dist/index.umd.js - UMD 格式dist/index.d.ts - TypeScript 类型声明文件MIT
欢迎提交 Issue 和 Pull Request!
yvygyyth
FAQs
A type-safe, extensible storage library with unified API supporting Memory, LocalStorage, SessionStorage, and IndexedDB
We found that store-vert demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.