A priority queue (binary heap) implementation in TypeScript with full type support. The constructor accepts an initial capacity and a custom comparator function, defaulting to max-heap. It supports add, poll, peek, contains, clear, toArray, iterable protocol, and dynamic resizing. Version 2.0.3 is the latest stable release; the package is actively maintained. Key differentiators: simple API, TypeScript-first, no runtime dependencies, supports ESM and CJS via CommonJS. Suitable for algorithmic tasks, stream processing, or any in-memory sorting needs.
npm install priority-queue-typescriptNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows creation of max-heap, min-heap with custom comparator, custom object usage, iteration, and size method.
If migrating from v1, pass initial capacity explicitly. v2 (current) uses capacity >0; default is 11 if omitted.
Always check for null after poll() when queue might be empty.
For max-heap: use default or (a, b) => b - a. For min-heap: use (a, b) => a - b.
Change 'import PriorityQueue from ...' to 'import { PriorityQueue } from ...'Ensure you use 'new PriorityQueue()' and that the variable is properly assigned.
Use initial capacity >= 1; e.g., new PriorityQueue<number>(10). Queue auto-grows but capacity 0 prevents initial add.
No dependency data recorded yet.