Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

local-db-storage

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-db-storage

IndexedDB wrapper that mimics localStorage API

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-90%
Maintainers
0
Weekly downloads
 
Created
Source

local-db-storage

IndexedDB wrapper 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 (25k stars) is complex and unmaintained.
  • I've been consistent in maintaining use-local-storage-state (400k downloads per month) for the past 4 years.

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.

Note: It supports non-primitive values (ex: objects). It also supports circular references.

removeItem(key: string): Promise<void>

Like localStorage.removeItem() but async.

clear(): Promise<void>

Like localStorage.clear() but async.

DBStorage(name: string)

Creates a new DBStorage instance.

import { DBStorage } from 'local-db-storage'

const dbStorage = new DBStorage('my-custom-db-storage')

await dbStorage.setItem('initial', 'hello world')

Keywords

FAQs

Package last updated on 16 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc