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 🙏

© 2025 – Pkg Stats / Ryan Hefner

idb-helper

v2.1.2

Published

A lightweight helper library for IndexedDB, making it as easy to use as LocalStorage.

Readme

🚀 idb-helper – The easiest way to work with IndexedDB! This library simplifies IndexedDB operations, making it as intuitive as LocalStorage while providing better performance and scalability for large datasets.

NPM Version License


⚠️ Warnings & Tips

🔹 IndexedDB operates asynchronously – Always use await when calling methods.
🔹 Be aware of browser limitations – Some browsers impose storage limits on IndexedDB.
🔹 Version management is crucial – If the database schema changes, older versions may face issues.
🔹 Bulk operations are more efficient – Use bulkInsert and bulkDelete for handling large datasets.
🔹 Indexed fields improve performancegetByIndex is faster than retrieving all items and filtering manually.
🔹 Use instead of LocalStorage – IndexedDB is a better choice for managing large amounts of data efficiently.


📦 Installation

Install via NPM:

npm install idb-helper

Install via Yarn:

yarn add idb-helper

Install via Bun:

bun add idb-helper

Or use CDN:

<script src="https://cdn.jsdelivr.net/npm/idb-helper/dist/index.global.js"></script>

🚀 Usage

🛠 IDBHelper – Full API Usage

import { IDBHelper } from "idb-helper";

const db = new IDBHelper("myDatabase", "myStore");

(async () => {
    // 1️⃣ Add a new item
    const id = await db.setItem({ id: 1, name: "Dilshod", age: 27 });
    console.log("New item ID:", id);

    // 2️⃣ Get an item by ID
    const user = await db.getItem(1);
    console.log("Fetched item:", user); // { id: 1, name: "Dilshod", age: 27 }

    // 3️⃣ Get all items
    const allUsers = await db.getAllItems();
    console.log("All items:", allUsers);

    // 4️⃣ Remove an item by ID
    await db.removeItem(1);
    console.log("Item removed.");

    // 5️⃣ Clear all data
    await db.clear();
    console.log("Database cleared.");

    // 6️⃣ Check if an item exists
    const exists = await db.hasItem(1);
    console.log("Item exists:", exists);

    // 7️⃣ Count total items
    const count = await db.count();
    console.log("Total items:", count);

    // 8️⃣ Update an item
    await db.updateItem(1, { name: "Dilshod", age: 28 });
    console.log("Item updated.");

    // 9️⃣ Get item by index
    const indexedItem = await db.getByIndex("name", "Dilshod");
    console.log("Item by index:", indexedItem);

    // 🔟 Get items by filter
    const filteredItems = await db.getItemsByFilter((item) => item.age > 25);
    console.log("Filtered items:", filteredItems);

    // 1️⃣1️⃣ Get items by range
    const rangedItems = await db.getItemsByRange("age", 20, 30);
    console.log("Items in range:", rangedItems);

    // 1️⃣2️⃣ Bulk insert multiple items
    await db.bulkInsert([
        { id: 2, name: "Ali", age: 23 },
        { id: 3, name: "Sara", age: 25 },
    ]);
    console.log("Bulk insert done.");

    // 1️⃣3️⃣ Bulk delete multiple items
    await db.bulkDelete([2, 3]);
    console.log("Bulk delete done.");

    // 1️⃣4️⃣ Close database
    await db.closeDB();
    console.log("Database closed.");
})();

🛠 Basic Usage in a React Component

Here’s how you can integrate idb-helper in a React component:

import React, { useEffect, useState } from "react";
import {IDBHelper} from "idb-helper";

const db = new IDBHelper("myDatabase", "myStore");

const App = () => {
    const [items, setItems] = useState([]);
    const [newItem, setNewItem] = useState("");

    // Load all items on component mount
    useEffect(() => {
        const fetchData = async () => {
            const allItems = await db.getAllItems();
            setItems(allItems);
        };
        fetchData();
    }, []);

    // Add a new item
    const handleAddItem = async () => {
        if (!newItem) return;
        const id = await db.setItem({ name: newItem });
        setItems([...items, { id, name: newItem }]);
        setNewItem("");
    };

    // Remove an item
    const handleRemoveItem = async (id) => {
        await db.removeItem(id);
        setItems(items.filter((item) => item.id !== id));
    };

    return (
        <div style={{ padding: "20px" }}>
            <h2>IndexedDB React Example</h2>
            <input
                type="text"
                value={newItem}
                onChange={(e) => setNewItem(e.target.value)}
                placeholder="Enter item name"
            />
            <button onClick={handleAddItem}>Add Item</button>
            <ul>
                {items.map((item) => (
                    <li key={item.id}>
                        {item.name} <button onClick={() => handleRemoveItem(item.id)}>❌</button>
                    </li>
                ))}
            </ul>
        </div>
    );
};

export default App;

🎯 Features

✅ Simplifies working with IndexedDB – No more complex transactions!
✅ Works with Promise API – Fully asynchronous and easy to use.
✅ Easy as LocalStorage – Simple setItem / getItem methods.
✅ Supports Indexed Queries – Fetch items by indexed fields.
✅ Advanced Filtering – Retrieve data using custom filter functions.
✅ Range Queries – Get items between a min/max value.
✅ Bulk Operations – Insert and delete multiple records at once.
✅ Database Management – Clear, count, and close the database easily.
✅ Super Fast – Optimized for large data storage.


📖 API

| Method | Type | Params | Returns | Description | |-----------------------|--------------------|-----------------------------------|---------------------------------|--------------------------------------------| | setItem<T> | Promise<number> | data: T & { id?: number } | id | Adds or updates an item in the database | | getItem<T> | Promise<T> | | id: number | T or undefined | Retrieves an item by ID | | getAllItems<T> | Promise<T[]> | none | T[] | Fetches all stored items | | removeItem | Promise<void> | id: number | void | Deletes an item by ID | | clear | Promise<void> | none | void | Clears all items from the database | | hasItem | Promise<boolean> | id: number | true/false | Checks if an item with the given ID exists | | count | Promise<number> | none | number | Returns the total number of stored items | | updateItem<T> | Promise<void> | id: number, updates: Partial<T> | void | Partially updates an item by ID | | getByIndex<T> | Promise<T> | | indexName: string, value: any | T or undefined | Retrieves an item using an index | | getItemsByFilter<T> | Promise<T[]> | filter: (item: T) => boolean | T[] | Fetches items that match a filter function | | getItemsByRange<T> | Promise<T[]> | startId: number, endId: number | T[] | Fetches items within an ID range | | bulkInsert<T> | Promise<void> | items: T[] | void | Inserts multiple items at once | | bulkDelete | Promise<void> | ids: number[] | void | Deletes multiple items at once | | closeDB | void | none | void | Closes the IndexedDB connection |


🛠️ Development and Testing

npm run dev   # Development mode
npm run build # Construction
npm run test  # Run tests

📜 License

MIT - Free and open source!

📌 Author: Dilshod Fayzullayev
📌 GitHub: bug4you/idb-helper