Registry / storage / idb-range

idb-range

JSON →
library3.1.3jsnpmunverified

MongoDB-inspired utility for constructing IndexedDB key ranges (IDBKeyRange) with a concise object notation. Version 3.1.3 is stable, with no active development since 2017. It simplifies range creation by accepting an object with gt/lt/gte/lte/eq properties or a plain value, reducing boilerplate over native IDBKeyRange methods. Lightweight, no dependencies, ESM-only, primarily for browser environments using IndexedDB.

npm install idb-range
INSTALL
IMPORT
SIG · IDB-RANGE
I
idb-range
storagejavascriptv3.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import range from 'idb-range'
const range = require('idb-range')
Package is ESM-only; CommonJS require will fail in strict Node environments.
default (as named)
import range from 'idb-range'
import { range } from 'idb-range'
The package exports a single default function, not a named export.
TypeScript usage
import range from 'idb-range'
import * as range from 'idb-range'
TypeScript with esModuleInterop: true or allowSyntheticDefaultImports: true; otherwise use import range = require('idb-range').

Shows how to import and use the default export to create an IDBKeyRange for a cursor query.

import range from 'idb-range'; // Create a range for keys from 'a' to 'z' inclusive const keyRange = range({ gte: 'a', lte: 'z' }); // Use with IndexedDB const request = indexedDB.open('db', 1); request.onsuccess = function() { const db = request.result; const tx = db.transaction('store', 'readonly'); const store = tx.objectStore('store'); const cursorRequest = store.openCursor(keyRange); cursorRequest.onsuccess = function() { const cursor = cursorRequest.result; if (cursor) { console.log(cursor.value); cursor.continue(); } }; };
Debug
Known issues
gotchaPassing an IDBKeyRange instance returns the same instance (no-op). This may cause unexpected behavior if you expect a new range or validation.
fix
Avoid passing IDBKeyRange instances; always use plain objects or values.
affects: >=0.0.0
gotchaCalling range() with no arguments returns null, not an undefined or error. Null may cause issues if passed directly to openCursor.
fix
Check for null before using in IndexedDB calls, or always provide valid parameters.
affects: >=0.0.0
deprecatedPackage is unmaintained since 2017. Vulnerabilities or future browser changes may not be addressed.
fix
Consider using native IDBKeyRange directly or an alternative active library.
affects: >=0.0.0
Errors
Common errors & fixes
export 'range' (imported as 'range') was not found in 'idb-range'
Incorrect named import instead of default import.
fix
Use `import range from 'idb-range'` (no braces).
Cannot find module 'idb-range'
Package not installed or path incorrect in Node.js with ESM.
fix
Run `npm install idb-range` and ensure `"type": "module"` in package.json or use .mjs extension.
TypeError: range is not a function
Using `require('idb-range')` which returns an object (ESM module) rather than the function.
fix
Use `import range from 'idb-range'` or enable dynamic import: `const range = (await import('idb-range')).default`.
Upgrade
Version history
3.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
24
Resources
idb-range — npm install idb-range · libregistry