@exodus/储存-记忆
《公约》的实际执行情况 统一存储光谱;作为概念证明和测试目的有用.
安装
pnpm add @exodus/storage-memory
使用量
import createStorage from '@exodus/storage-memory'
const storage = createStorage()
// use as any other `@exodus/storage-spec` compliant interface
有时在测试期间,获得对存储内容的更多控制会有所帮助:
import createStorage from '@exodus/storage-memory'
import BJSON from 'buffer-json'
// advanced options:
const store = new Map([['my-favorite-prefix!a', 1]])
const storage = createStorage({
// `storage` will write to this `store` instead of a private encapsulated Map
store,
prefix: 'my-favorite-prefix!',
// by default, storage-memory validate values are POJOs on write
skipValueValidation: true,
// if you need custom serialization
transformOnWrite = BJSON.stringify,
transformOnRead = BJSON.parse,
})
const a = await storage.get('a')
// a === 1