Skip to main content

@exodus/storage-memory

An in-memory implementation of the unified storage spec; useful as a proof-of-concept and for testing purposes.

Install

yarn add @exodus/storage-memory

Usage

import createStorage from '@exodus/storage-memory'

const storage = createStorage()
// use as any other `@exodus/storage-spec` compliant interface

Sometimes during testing, it can be helpful to get more control over storage contents:

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