
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
browser-indexeddb
Advanced tools
A simple, type-safe IndexedDB wrapper with MongoDB-like API for browser applications
A simple, type-safe IndexedDB wrapper with MongoDB-like API for browser applications. Zero dependencies, fully typed, with familiar query operators.
$eq, $gt, $in, $regex, etc.)npm install browser-indexeddb
yarn add browser-indexeddb
For schema validation (optional):
npm install zod
Traditional Script Tag (no module):
<script src="https://unpkg.com/browser-indexeddb@latest/dist/index.global.js"></script>
<script>
// BrowserDB is available globally on window
const db = new BrowserDB('my-app-db');
db.connect().then(async function () {
console.log('Connected!');
await db.collection('visitors').insert({
userAgent: navigator.userAgent,
time: new Date(),
});
});
</script>
ES Module:
<script type="module">
import { BrowserDB } from 'https://unpkg.com/browser-indexeddb@latest/dist/index.mjs';
const db = new BrowserDB('my-app-db');
await db.connect();
await db.collection('visitors').insert({
userAgent: navigator.userAgent,
time: new Date(),
});
</script>
import { BrowserDB, Document } from 'browser-indexeddb';
interface User extends Document {
_id: string;
name: string;
email: string;
age: number;
}
// Create database - auto-connects!
const db = new SimpleDB('my-app');
// Optional: wait for connection if you need it immediately
await db.connect();
const users = db.collection<User>('users');
// Insert
const user = await users.insert({
name: 'John Doe',
email: 'john@example.com',
age: 30,
});
// Find
const found = await users.findOne({ email: 'john@example.com' });
// Update
await users.updateById(user._id, { $set: { age: 31 } });
// Delete
await users.deleteById(user._id);
db.close();
const db = new SimpleDB('database-name');
// Connection (auto-connects, but can await if needed)
await db.connect(); // Wait for connection
db.close(); // Close connection
db.isConnected(); // Check connection status
// Collections
db.collection<T>('name', {schema?}); // Get typed collection
db.listCollections(); // List all collections
db.hasCollection('name'); // Check if exists
await db.dropCollection('name'); // Delete collection
await db.drop(); // Delete entire database
// Insert
await collection.insert(doc); // Insert with duplicate check
await collection.insertFast(doc); // Skip duplicate check (faster)
await collection.insertMany(docs); // Bulk insert
// Find
await collection.find(query?, options?); // Find matching docs
await collection.findOne(query); // Find first match
await collection.findById(id); // Find by ID
await collection.count(query?); // Count matches
await collection.getAll(); // Get all documents
// Update
await collection.update(query, update); // Update many
await collection.updateOne(query, update); // Update first match
await collection.updateById(id, update); // Update by ID
// Delete
await collection.delete(query); // Delete many
await collection.deleteOne(query); // Delete first match
await collection.deleteById(id); // Delete by ID
await collection.clear(); // Clear all documents
await collection.drop(); // Drop collection
| Operator | Example |
|---|---|
$eq | { age: { $eq: 25 } } |
$ne | { status: { $ne: 'deleted' } } |
$gt / $gte | { age: { $gte: 18 } } |
$lt / $lte | { price: { $lt: 100 } } |
$in / $nin | { role: { $in: ['admin', 'mod'] } } |
| Operator | Example |
|---|---|
$regex | { email: { $regex: /@gmail\.com$/ } } |
$startsWith | { name: { $startsWith: 'John' } } |
$endsWith | { email: { $endsWith: '.com' } } |
// AND (implicit)
{ active: true, age: { $gte: 18 } }
// OR
{ $or: [{ role: 'admin' }, { role: 'mod' }] }
// NOT
{ $not: { status: 'deleted' } }
{
email: {
$exists: true;
}
} // Field exists
{
deletedAt: {
$exists: false;
}
} // Field doesn't exist
| Operator | Description | Example |
|---|---|---|
$set | Set field | { $set: { name: 'New' } } |
$unset | Remove field | { $unset: { temp: true } } |
$inc | Increment | { $inc: { views: 1 } } |
$push | Add to array | { $push: { tags: 'new' } } |
$pull | Remove from array | { $pull: { tags: 'old' } } |
$addToSet | Add unique | { $addToSet: { tags: 'unique' } } |
import { z } from 'zod';
import { SimpleDB, ValidationError } from 'browser-indexeddb';
const UserSchema = z.object({
_id: z.string().optional(),
name: z.string().min(1),
email: z.string().email(),
role: z.enum(['admin', 'user']).optional(),
});
type User = z.infer<typeof UserSchema>;
const db = new SimpleDB('my-app');
await db.connect();
const users = db.collection<User>('users', { schema: UserSchema });
// ✅ Valid - inserts successfully
await users.insert({ name: 'John', email: 'john@example.com' });
// ❌ Invalid - throws ValidationError
try {
await users.insert({ name: '', email: 'not-an-email' });
} catch (error) {
if (error instanceof ValidationError) {
console.log(error.issues);
}
}
Data is stored in IndexedDB, which provides:
# Install dependencies
yarn install
# Run unit tests (vitest + fake-indexeddb)
yarn test
# Run browser tests (Playwright)
yarn test:browser
yarn test:browser:headed # with browser UI
# Run all tests
yarn test:all
# Run examples (uses fake-indexeddb for Node.js)
yarn example:basic
yarn example:zod
# Build
yarn build
# Lint
yarn lint
# Type check
yarn typecheck
MIT © Rashed Iqbal
FAQs
A simple, type-safe IndexedDB wrapper with MongoDB-like API for browser applications
We found that browser-indexeddb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.