Minimalist priority queue implementation using a binary heap, written in TypeScript. Version 1.2.0 ships with type definitions and supports both max-heap (default) and min-heap via custom comparator. The library is small (under 1KB gzipped), has zero dependencies, and targets Node >=8. It provides a basic API (push, pop, top, size) common to LeetCode-style problems. Compared to alternatives like @datastructures-js/priority-queue or js-priority-queue, this package is simpler and less feature-rich, but it remains actively maintained as of 2025.
npm install p-queue-tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates max-heap and min-heap usage with numbers and objects, including push, pop, top, and size methods.
If you want a min-heap of numbers, pass (a, b) => a > b. For objects, compare the priority field appropriately.
Use top() to get the highest-priority element without removal.
If you need dynamic priority updates, consider using a different library like @datastructures-js/priority-queue.
Call size() as a method, e.g., const len = pq.size();
Use (a, b) => a > b for min-heap or (a, b) => a < b for max-heap (default).
Replace pq.size with pq.size()
Use (a, b) => a > b (for min-heap) or (a, b) => a < b (for max-heap).
Run 'npm install p-queue-ts' and use correct import: import { PriorityQueue } from 'p-queue-ts'Use named import: import { PriorityQueue } from 'p-queue-ts'No dependency data recorded yet.