A priority queue data structure implemented in TypeScript, providing O(log n) insertion and removal. Version 0.1.1 is the current stable release. The library uses a binary heap strategy and is a port of the CoffeeScript js-priority-queue, with array and BHeap strategies removed. It offers a simple API: queue, dequeue, peek, clear, and length. Supports custom comparators and initial values. Ideal for TypeScript projects needing a minimal, dependency-free priority queue. However, it is a small, possibly unmaintained package with limited testing and documentation.
npm install ts-priority-queueNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a min-heap and max-heap priority queue, adding elements, peeking, dequeuing, and clearing.
Explicitly provide comparator: new PriorityQueue({ comparator: (a, b) => b - a }) for max-heap.Ensure comparator returns a number (negative, zero, or positive), not a boolean.
Use explicit type parameter: new PriorityQueue<number>()
Use inline object: { comparator?: (a: T, b: T) => number; initialValues?: T[] }Use const { PriorityQueue } = require('ts-priority-queue');new PriorityQueue<number>() instead of using default any.
const queue = new PriorityQueue(); queue.length works.
No dependency data recorded yet.