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.

storage
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.

Only named export is available; no default export.

import { SortedQueue } from 'sorted-queue'

When only using the type, use type import to avoid runtime overhead.

import type { SortedQueue } from 'sorted-queue'

Package is ESM-only; dynamic import is required in CommonJS.

const { SortedQueue } = await import('sorted-queue')

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 footguns
breakingNode.js version requirement >= 22
breakingESM-only package, no CommonJS support
deprecatedPackage is in maintenance mode; no new features accepted.
gotchaRemoving items by reference via item.pop() is O(1) but not obvious
gotchapop() and peek() return undefined when queue is empty, not throw
gotchapush() returns an object containing value and pop method; mutating value does not reorder
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources