Registry / devops / js-priority-queue

js-priority-queue

JSON →
library0.1.5jsnpmunverified

A priority queue data structure library for JavaScript (v0.1.5) offering Array, BinaryHeap, and BHeap strategies. Provides standard operations: queue, dequeue, peek, clear, and length. Ideal for managing ordered data efficiently; defaults to BinaryHeap for O(log n) insert and extract. Lightweight, dependency-free, works in Node.js and browsers via CommonJS/AMD/global. Last updated in 2014, considered stable but unmaintained.

npm install js-priority-queue
INSTALL
IMPORT
SIG · JS-PRIORITY-QUEUE
J
js-priority-queue
devopsjavascriptv0.1.5
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.

PriorityQueue
import PriorityQueue from 'js-priority-queue';
const { PriorityQueue } = require('js-priority-queue');
Default export is the PriorityQueue constructor.
PriorityQueue.ArrayStrategy
import PriorityQueue from 'js-priority-queue'; const strategy = PriorityQueue.ArrayStrategy;
const { ArrayStrategy } = require('js-priority-queue');
Strategies are static properties on PriorityQueue, not separate exports.
PriorityQueue.BinaryHeapStrategy
import PriorityQueue from 'js-priority-queue'; const strategy = PriorityQueue.BinaryHeapStrategy;
import { BinaryHeapStrategy } from 'js-priority-queue';
BinaryHeapStrategy is a static property, not a named export.
PriorityQueue.BHeapStrategy
import PriorityQueue from 'js-priority-queue'; const strategy = PriorityQueue.BHeapStrategy;
import { BHeapStrategy } from 'js-priority-queue';
BHeapStrategy is a static property, not a named export.

Creates a min-heap priority queue with initial values, queues an element, dequeues smallest elements, and clears the queue.

import PriorityQueue from 'js-priority-queue'; const queue = new PriorityQueue({ comparator: (a, b) => a - b, // min-heap initialValues: [5, 3, 2] }); queue.queue(1); const len = queue.length; // 4 const smallest = queue.dequeue(); // 1 const next = queue.dequeue(); // 2 queue.clear(); console.log('Done');
Debug
Known issues
breakingVersion 0.1.x uses CJS/global export; no ESM entry point. Importing with ESM in modern bundlers may fail.
fix
Use CommonJS require or configure bundler to handle CJS.
affects: >=0.1.0 <=0.1.5
deprecatedStrategy property names are not type-safe in TypeScript; library lacks TypeScript definitions.
fix
Add custom type declarations or use @types/js-priority-queue if available (none exists).
affects: >=0.1.0
gotchaThe constructor throws if neither 'comparator' nor default order is provided; default comparator is not documented clearly.
fix
Always provide a comparator function.
affects: >=0.1.0
gotchaQueue does not handle large numbers of items efficiently if using ArrayStrategy; performance may degrade with many elements.
fix
Use BinaryHeapStrategy (default) for most cases.
affects: >=0.1.0
deprecatedLibrary last updated in 2014; no ongoing maintenance, may have unpatched edge cases.
fix
Consider modern alternatives like @datastructures-js/priority-queue or flatqueue.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: PriorityQueue is not a constructor
Incorrect import or require path; or using ESM import with CJS-only version.
fix
Use `const PriorityQueue = require('js-priority-queue');` or configure bundler for CJS.
Uncaught Error: No strategy found
Invalid strategy passed to constructor; strategy property is not a valid value.
fix
Use one of: PriorityQueue.ArrayStrategy, PriorityQueue.BinaryHeapStrategy, PriorityQueue.BHeapStrategy.
Uncaught Error: comparator requires a function or object with a comparator property
Missing 'comparator' option in constructor.
fix
Provide a comparator function like `(a, b) => a - b`.
TypeError: queue.dequeue is not a function
Using 'dequeue' on an object that is not a valid PriorityQueue instance.
fix
Ensure queue was created correctly: `const queue = new PriorityQueue({ comparator: ... });`
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
js-priority-queue — npm install js-priority-queue · libregistry