# tinyqueue

> The smallest and simplest JavaScript priority queue

Latest version **3.0.0** (published 2024-07-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install tinyqueue
pnpm add tinyqueue
yarn add tinyqueue
bun add tinyqueue
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-07-06 |
| First published | 2015-04-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 468 |
| Maintainers | mourner |
| Keywords | queue, priority, binary heap, data structures |

## Links

- npm: https://www.npmjs.com/package/tinyqueue
- Repository: https://github.com/mourner/tinyqueue
- Issues: https://github.com/mourner/tinyqueue/issues
- npm.io page: https://npm.io/package/tinyqueue

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2024-07-06
- 2.0.3 — 2019-06-14
- 2.0.2 — 2019-04-05
- 2.0.1 — 2019-04-05
- 2.0.0 — 2018-08-08
- 1.2.3 — 2017-10-10
- 1.2.2 — 2017-03-16
- 1.2.1 — 2017-03-16
- 1.2.0 — 2017-03-15
- 1.1.0 — 2016-02-11
- 1.0.1 — 2015-04-24
- 1.0.0 — 2015-04-23

## README

## tinyqueue

The smallest and simplest binary heap priority queue in JavaScript.

```js
// create an empty priority queue
var queue = new TinyQueue();

// add some items
queue.push(7);
queue.push(5);
queue.push(10);

// remove the top item
var top = queue.pop(); // returns 5

// return the top item (without removal)
top = queue.peek(); // returns 7

// get queue length
queue.length; // returns 2

// create a priority queue from an existing array (modifies the array)
queue = new TinyQueue([7, 5, 10]);

// pass a custom item comparator as a second argument
queue = new TinyQueue([{value: 5}, {value: 7}], function (a, b) {
	return a.value - b.value;
});

// turn a queue into a sorted array
var array = [];
while (queue.length) array.push(queue.pop());
```

For a faster number-based queue, see [flatqueue](https://github.com/mourner/flatqueue).

### Install

Install using NPM (`npm install tinyqueue`) or Yarn (`yarn add tinyqueue`), then:

```js
// import as an ES module
import TinyQueue from 'tinyqueue';

// or require in Node / Browserify
const TinyQueue = require('tinyqueue');
```

Or use a browser build directly:

```html
<script src="https://unpkg.com/tinyqueue@2.0.0/tinyqueue.min.js"></script>
```

### Thanks

Inspired by [js-priority-queue](https://github.com/adamhooper/js-priority-queue)
by [Adam Hooper](https://github.com/adamhooper).

---
_Source: https://npm.io/package/tinyqueue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
