Storage
/ API ReferenceStorage
/ API ReferencecreateIndexedStorage
A convenience helper to create an IndexedDB 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
| Parameter | Type | Description |
|---|---|---|
| database | string | The name of the database to use. |
| table | string | The 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
| Parameter | Type | Description |
|---|---|---|
| key | string | The key of the item to set. |
| value | any | The value of the item to set. |
getItem
An async function to get an item from the storage.
Parameters
| Parameter | Type | Description |
|---|---|---|
| key | string | The key of the item to get. |
| value | any | The 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
| Parameter | Type | Description |
|---|---|---|
| key | string | The key of the item to remove. |
| value | any | The value of the item to remove. |
clear
An async function to clear the storage.
Parameters
| Parameter | Type | Description |
|---|---|---|
| key | string | The key of the item to clear. |
| value | any | The value of the item to clear. |
© 2024-present Robin Weser. All Rights Reserved.