npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

indexeddb-storage-lib

v1.0.0

Published

A lightweight wrapper for IndexedDB with TypeScript support.

Readme

IndexedDB Storage Lib

A lightweight wrapper for IndexedDB with TypeScript support.

Installation

npm install indexeddb-storage-lib

Usage

ES Module

import IndexedDBWrapper from "indexeddb-storage-lib";

async function run() {
  try {
    const db = await IndexedDBWrapper.getInstance("myDatabase", "myStore");

    // Add an item
    const id = await db.addItem({ name: "Test Item" });
    console.log("Added item with id:", id);

    // Get all items
    const items = await db.getAllItems();
    console.log("All items:", items);
  } catch (error) {
    console.error("Error:", error);
  }
}

run();

CommonJS

const IndexedDBWrapper = require("indexeddb-storage-lib");

async function run() {
  try {
    const db = await IndexedDBWrapper.getInstance("myDatabase", "myStore");

    // Add an item
    const id = await db.addItem({ name: "Test Item" });
    console.log("Added item with id:", id);

    // Get all items
    const items = await db.getAllItems();
    console.log("All items:", items);
  } catch (error) {
    console.error("Error:", error);
  }
}

run();

React

import React, { useEffect, useState } from 'react';
import IndexedDBWrapper from 'indexeddb-storage-lib';

const App = () => {
  const [items, setItems] = useState([]);
  const [dbInstance, setDbInstance] = useState(null);

  // 获取实例并初始化数据库
  const initializeDB = async () => {
    try {
      const db = await IndexedDBWrapper.getInstance('myDatabase', 'myStore');
      setDbInstance(db);
    } catch (error) {
      console.error('Error initializing DB:', error);
    }
  };

  useEffect(() => {
    initializeDB();
  }, []);

  // 添加一个项
  const addItem = async () => {
    try {
      if (dbInstance) {
        const id = await dbInstance.addItem({ name: 'React Test Item' });
        console.log('Added item with id:', id);
      }
    } catch (error) {
      console.error('Error adding item:', error);
    }
  };

  // 获取所有项
  const getAllItems = async () => {
    try {
      if (dbInstance) {
        const allItems = await dbInstance.getAllItems();
        setItems(allItems);
        console.log('All items:', allItems);
      }
    } catch (error) {
      console.error('Error getting items:', error);
    }
  };

  return (
    <div>
      <button onClick={addItem}>Add Item</button>
      <button onClick={getAllItems}>Get All Items</button>
      <div>
        {items.length > 0 && (
          <div>
            <h3>All Items:</h3>
            <ul>
              {items.map((item, index) => (
                <li key={index}>{item.name}</li>
              ))}
            </ul>
          </div>
        )}
      </div>
    </div>
  );
};

export default App;

Vue

<template>
  <div>
    <button @click="addItem">Add Item</button>
    <button @click="getAllItems">Get All Items</button>
    <div v-if="items.length">
      <h3>All Items:</h3>
      <ul>
        <li v-for="(item, index) in items" :key="index">{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue';
import IndexedDBWrapper from 'indexeddb-storage-lib';

export default {
  setup() {
    const items = ref([]);
    const dbInstance = ref(null);

    // 获取实例并初始化数据库
    const initializeDB = async () => {
      try {
        dbInstance.value = await IndexedDBWrapper.getInstance('myDatabase', 'myStore');
      } catch (error) {
        console.error('Error initializing DB:', error);
      }
    };

    // 添加一个项
    const addItem = async () => {
      try {
        const id = await dbInstance.value.addItem({ name: 'Vue Test Item' });
        console.log('Added item with id:', id);
      } catch (error) {
        console.error('Error adding item:', error);
      }
    };

    // 获取所有项
    const getAllItems = async () => {
      try {
        items.value = await dbInstance.value.getAllItems();
        console.log('All items:', items.value);
      } catch (error) {
        console.error('Error getting items:', error);
      }
    };

    // 初始化数据库
    initializeDB();

    return {
      items,
      addItem,
      getAllItems
    };
  }
};
</script>

API

getInstance(dbName: string, storeName: string, dbVersion?: number): IndexedDBWrapper

Returns a singleton instance of the IndexedDBWrapper.

addItem<T>(item: T): Promise<IDBValidKey>

Adds an item to the store and returns its ID.

getItem<T>(id: IDBValidKey): Promise<T | undefined>

Retrieves an item by ID.

getAllItems<T>(): Promise<T[]>

Retrieves all items in the store.

deleteItem(id: IDBValidKey): Promise<void>

Deletes an item by ID.

License

MIT