local-db-storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

local-db-storage

Tiny wrapper around IndexedDB that mimics localStorage API

Gzipped Size Build Status

Install

npm install local-db-storage

Why

  • If you want to use IndexedDB but don't want to deal with its complex API.
  • If you want to store more data than what localStorage supports but still want the same API.
  • The most popular library localForage is bloated and unmaintained.

Usage

import dbStorage from 'local-db-storage'

async function addTodo(todo): Promise<void> {
    await dbStorage.setItem(todo.id, todo)
}

async function getTodo(id: string): Promise<Todo> {
    await dbStorage.getItem<Todo>(id)
}

API

getItem<T>(key: string): Promise<T>

Like localStorage.getItem() but async.

setItem(key: string, value: any): Promise<void>

Like localStorage.setItem() but async. It supports non-primitive values like objects. It also supports circular references.

removeItem(key: string): Promise<void>

Like localStorage.removeItem() but async.

clear(): Promise<void>

Like localStorage.clear() but async.

Related

Package Sidebar

Install

npm i local-db-storage

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.56 kB

Total Files

9

Last publish

Collaborators

  • astoilkov