Storage
/ API Reference
Storage
/ API Reference

createIndexedStorage

A convenience helper to create an IndexedDB (new tab) storage instance.

The Gist

import { createIndexedStorage } from '@weser/storage'

const storage = createIndexedStorage('my-database', 'my-table')

await storage.setItem('dark-mode', true)
const mode = await storage.getItem('dark-mode')
await storage.removeItem('dark-mode')
await storage.clear()

Parameters

ParameterTypeDescription
databasestringThe name of the database to use.
tablestringThe name of the table to use.

Returns

(Object) An object with the following properties:

setItem

An async function to set an item in the storage.

Parameters

ParameterTypeDescription
keystringThe key of the item to set.
valueanyThe value of the item to set.

getItem

An async function to get an item from the storage.

Parameters

ParameterTypeDescription
keystringThe key of the item to get.
valueanyThe value of the item to get.

Returns

(Promise<any>) A promise that resolves with the item.

removeItem

Ann async function to remove an item from the storage.

Parameters

ParameterTypeDescription
keystringThe key of the item to remove.
valueanyThe value of the item to remove.

clear

An async function to clear the storage.

Parameters

ParameterTypeDescription
keystringThe key of the item to clear.
valueanyThe value of the item to clear.
On this page