Registry / database / tinyqueue

tinyqueue

JSON →
library3.0.0jsnpmunverified

tinyqueue is a lightweight, efficient JavaScript library providing a binary heap-based priority queue data structure. Currently at version 3.0.0, it offers fundamental operations like `push`, `pop`, and `peek` with minimal overhead. The library's core design prioritizes simplicity and a small bundle size, distinguishing it from more feature-rich or specialized queue implementations. It supports custom comparison functions, allowing users to define priority based on object properties rather than just raw values. While release cadence is not strictly regular, it sees updates for performance improvements and compatibility, with the most recent major update (v3.0.0) shifting to an ES module-only distribution.

npm install tinyqueue
INSTALL
IMPORT
SIG · TINYQUEUE
T
tinyqueue
databasejavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

TinyQueue
import TinyQueue from 'tinyqueue';
const TinyQueue = require('tinyqueue');
Since v3.0.0, tinyqueue is published exclusively as an ES module. CommonJS `require()` is no longer supported and will result in an error in modern Node.js environments. TypeScript types are bundled and automatically available for this default export.

Demonstrates how to initialize a TinyQueue, add elements, retrieve the highest priority item, inspect the queue's length, and use custom comparators for complex objects, including how to turn a queue into a sorted array.

import TinyQueue from 'tinyqueue'; // Create an empty priority queue const queue = new TinyQueue(); // Add some items queue.push(7); queue.push(5); queue.push(10); console.log('Initial top item:', queue.peek()); // Expected: 5 // Remove the top item const top = queue.pop(); // Returns 5 console.log('Popped item:', top); console.log('Current top item:', queue.peek()); // Expected: 7 console.log('Queue length:', queue.length); // Expected: 2 // Create a priority queue from an existing array const initialArrayQueue = new TinyQueue([7, 5, 10]); console.log('Queue from array, top:', initialArrayQueue.peek()); // Expected: 5 // Pass a custom item comparator for objects const customQueue = new TinyQueue([{value: 5}, {value: 7}, {value: 3}], function (a, b) { return a.value - b.value; }); console.log('Custom queue top item value:', customQueue.peek().value); // Expected: 3 // Turn a queue into a sorted array by repeatedly popping const sortedArray = []; while (customQueue.length) { sortedArray.push(customQueue.pop().value); } console.log('Sorted array from queue:', sortedArray); // Expected: [3, 5, 7]
Debug
Known issues
breakingVersion 3.0.0 removed CommonJS and UMD distribution support. The package is now exclusively published as an ES module.
fix
Migrate your project to use ES module imports (e.g., `import TinyQueue from 'tinyqueue';`). Ensure your Node.js environment or build tool supports ES modules. For browser usage without a build step, load via a CDN that provides ESM compatibility or bundle it with a tool like Rollup/Webpack.
affects: >=3.0.0
gotchaFor use cases strictly involving numerical priority queues where extreme performance is critical, the `flatqueue` library (from the same author) offers a potentially faster, specialized alternative.
fix
Evaluate `flatqueue` if `tinyqueue`'s general-purpose binary heap performance does not meet specific, high-frequency numerical processing requirements.
affects: >=1.0.0
gotchaWhen initializing a `TinyQueue` from an existing array, the input array is mutated (rearranged internally) by the queue's constructor to create the heap. This means the original array reference will point to a modified array.
fix
If you need to preserve the original array, pass a shallow copy to the constructor: `new TinyQueue([...myArray], comparator)`.
affects: All
Errors
Common errors & fixes
TypeError: require is not a function
Attempting to import `tinyqueue` using CommonJS `require()` syntax (e.g., `const TinyQueue = require('tinyqueue');`) in an ES module context or Node.js environment configured for ES modules (e.g., `"type": "module"` in package.json) since v3.0.0.
fix
Change the import statement to `import TinyQueue from 'tinyqueue';`. Ensure your project's `package.json` correctly specifies `"type": "module"` if you are using Node.js ES modules, or adjust your build system accordingly.
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './tinyqueue.min.js' is not defined by 'exports' in .../node_modules/tinyqueue/package.json
Attempting to directly reference UMD or CJS browser bundles, which were removed in v3.0.0. This error typically occurs when trying to load the library directly in a browser via a script tag referencing a local file or an outdated CDN path.
fix
For browser usage without a build system, use a modern CDN that provides ES module builds (e.g., `https://cdn.jsdelivr.net/npm/tinyqueue@3/tinyqueue.mjs`). If using a build system, import `tinyqueue` as an ES module and let your bundler handle it.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Meta
1
Amazon
1
OpenAI (training)
1
Resources
tinyqueue — npm install tinyqueue · libregistry