Registry / storage / sorted-queue

sorted-queue

JSON →
library0.4.4jsnpmunverified

A sorted queue implementation based on an array-backed binary heap. Version 0.4.4 is the current stable release, but the package is in maintenance mode with no new features accepted. It is designed for Node.js >= 22 and ships TypeScript types. Key differentiators: items can be removed by reference (via item.pop()), supports custom comparator functions, and operates in O(log n) time for push/pop. It is ESM-only and lightweight with no dependencies.

npm install sorted-queue
INSTALL
IMPORT
SIG · SORTED-QUEUE
S
sorted-queue
storagejavascriptv0.4.4
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.

SortedQueue
import { SortedQueue } from 'sorted-queue'
import SortedQueue from 'sorted-queue'
Only named export is available; no default export.
SortedQueue (type)
import type { SortedQueue } from 'sorted-queue'
import { SortedQueue } from 'sorted-queue'
When only using the type, use type import to avoid runtime overhead.
CommonJS require
const { SortedQueue } = await import('sorted-queue')
const { SortedQueue } = require('sorted-queue')
Package is ESM-only; dynamic import is required in CommonJS.

Shows basic usage: creating a sorted queue, push/pop/peek/empty, custom comparator, and removing items by reference.

import { SortedQueue } from 'sorted-queue'; const queue = new SortedQueue<number>(); queue.push(3); queue.push(1); queue.push(2); console.log(queue.pop().value); // 1 console.log(queue.peek().value); // 2 console.log(queue.empty()); // false queue.pop(); queue.pop(); console.log(queue.empty()); // true // Using custom comparator const custom = new SortedQueue<string>((a, b) => b.localeCompare(a)); custom.push('c'); custom.push('a'); custom.push('b'); console.log(custom.pop().value); // 'c' // Removing specific item const item = queue.push(42); item.pop(); // removes 42 queue.pop(); // undefined (queue empty)
Debug
Known issues
breakingNode.js version requirement >= 22
fix
Upgrade Node.js to version 22 or later.
affects: >=0.4.0
breakingESM-only package, no CommonJS support
fix
Use import syntax or dynamic import in CommonJS.
affects: >=0.4.0
deprecatedPackage is in maintenance mode; no new features accepted.
fix
Consider alternative packages if new features are needed.
affects: >=0.0.0
gotchaRemoving items by reference via item.pop() is O(1) but not obvious
fix
Use the returned item object to remove an arbitrary element from the queue.
affects: >=0.0.0
gotchapop() and peek() return undefined when queue is empty, not throw
fix
Check with empty() or ensure queue is not empty before calling pop/peek.
affects: >=0.0.0
gotchapush() returns an object containing value and pop method; mutating value does not reorder
fix
Do not mutate pushed objects expecting re-sort; remove and re-insert.
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only package.
fix
Use import { SortedQueue } from 'sorted-queue' or dynamic import.
TypeError: SortedQueue is not a constructor
Importing default instead of named export.
fix
Use import { SortedQueue } from 'sorted-queue' (curly braces).
TypeError: queue.push is not a function
Forgot to instantiate SortedQueue or imported incorrectly.
fix
Instantiate: const queue = new SortedQueue();
error:0308010C:digital envelope routines::unsupported
OpenSSL compatibility issue in older Node.js versions (pre-22).
fix
Upgrade Node.js to >=22 or set NODE_OPTIONS=--openssl-legacy-provider (temporary).
Upgrade
Version history
0.4.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
sorted-queue — npm install sorted-queue · libregistry