🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

fake-indexeddb

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fake-indexeddb

Fake IndexedDB: a pure JS in-memory implementation of the IndexedDB API

6.0.1
latest
Source
npm
Version published
Weekly downloads
866K
-1.56%
Maintainers
1
Weekly downloads
 
Created

What is fake-indexeddb?

The fake-indexeddb npm package is a mock implementation of the IndexedDB API, which is useful for testing and development purposes. It allows developers to simulate IndexedDB operations without relying on a real browser environment.

What are fake-indexeddb's main functionalities?

Creating a Database

This feature allows you to create a new IndexedDB database and an object store within it. The code sample demonstrates how to open a database, handle the upgrade event to create an object store, and log the success event.

const { indexedDB } = require('fake-indexeddb');
const request = indexedDB.open('test-db', 1);
request.onupgradeneeded = function(event) {
  const db = event.target.result;
  db.createObjectStore('store', { keyPath: 'id' });
};
request.onsuccess = function(event) {
  const db = event.target.result;
  console.log('Database created:', db);
};

Adding Data to Object Store

This feature allows you to add data to an object store within the IndexedDB database. The code sample demonstrates how to open a database, create a transaction, add data to the object store, and log the completion of the transaction.

const { indexedDB } = require('fake-indexeddb');
const request = indexedDB.open('test-db', 1);
request.onsuccess = function(event) {
  const db = event.target.result;
  const transaction = db.transaction('store', 'readwrite');
  const store = transaction.objectStore('store');
  store.add({ id: 1, name: 'John Doe' });
  transaction.oncomplete = function() {
    console.log('Data added');
  };
};

Retrieving Data from Object Store

This feature allows you to retrieve data from an object store within the IndexedDB database. The code sample demonstrates how to open a database, create a transaction, retrieve data from the object store, and log the retrieved data.

const { indexedDB } = require('fake-indexeddb');
const request = indexedDB.open('test-db', 1);
request.onsuccess = function(event) {
  const db = event.target.result;
  const transaction = db.transaction('store', 'readonly');
  const store = transaction.objectStore('store');
  const getRequest = store.get(1);
  getRequest.onsuccess = function() {
    console.log('Data retrieved:', getRequest.result);
  };
};

Other packages similar to fake-indexeddb

Keywords

indexeddb

FAQs

Package last updated on 10 May 2025

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