npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@surihoney/priority-queue

v0.1.1

Published

Two-tier priority queue with stable FIFO ordering and position-preserving reinsert

Downloads

286

Readme

@surihoney/priority-queue

npm version

A small TypeScript library for ordering items in a priority queue — a waiting line where more important items go first, but everyone still gets a fair turn within their group.

Install

Published on npm: @surihoney/priority-queue

npm install @surihoney/priority-queue

Or with another package manager:

yarn add @surihoney/priority-queue
pnpm add @surihoney/priority-queue

Then import in your project:

import { insertItem, reinsertItem, PriorityRank } from '@surihoney/priority-queue';

No extra setup required — TypeScript types are included.

What is a priority queue?

Imagine a coffee shop line:

  • VIP customers get served before regular customers.
  • Among VIPs, whoever arrived first is served first.
  • Among regular customers, same rule — first come, first served.

That is a priority queue: items are sorted by importance first, then by arrival order.

Key terms

| Term | Meaning | |------|---------| | Priority rank | A number that says how important an item is. Lower number = higher priority. (e.g. 0 = VIP, 1 = normal) | | Priority band / tier | A group of items that share the same priority rank (e.g. all VIPs, all normal) | | FIFO | First In, First Out — within the same priority band, earlier items stay ahead of later ones | | Insert | Add a new item. It goes to the back of its priority band. | | Reinsert | Put an item back after it was removed (e.g. interrupted work). It returns to its original spot based on its id, so it does not unfairly jump ahead of newer items. |

Why two functions?

This library gives you two operations on purpose:

  • insertItem — for brand-new work. New VIPs join the end of the VIP line; new normal items join the end of the normal line.
  • reinsertItem — for work that was paused and resumed. It goes back where it would have been if it had never left, using id order within the same priority band.

Simplest example

import {
  insertIdentifiedItem,
  PriorityRank,
  type IdentifiedQueueItem,
} from '@surihoney/priority-queue';

let queue: IdentifiedQueueItem[] = [];

// Two normal customers join the line
queue = insertIdentifiedItem(queue, { id: 1, priority: PriorityRank.normal });
queue = insertIdentifiedItem(queue, { id: 2, priority: PriorityRank.normal });
// queue: [1, 2]

// A VIP arrives — they go to the front
queue = insertIdentifiedItem(queue, { id: 3, priority: PriorityRank.high });
// queue: [3, 1, 2]  → VIP first, then normal customers in order

Custom items

You can queue any shape of object. You only need to tell the library how to read each item's priority:

import { insertItem, reinsertItem } from '@surihoney/priority-queue';

interface Order {
  id: number;
  tier: 'VIP' | 'NORMAL';
}

const options = {
  getPriorityRank: (order: Order) => (order.tier === 'VIP' ? 0 : 1),
};

let queue: Order[] = [];

queue = insertItem(queue, { id: 1, tier: 'NORMAL' }, options);
queue = insertItem(queue, { id: 2, tier: 'VIP' }, options);
// [{ id: 2, tier: 'VIP' }, { id: 1, tier: 'NORMAL' }]

// Customer 1 stepped away and came back — they keep their place among normals
queue = reinsertItem(
  [{ id: 3, tier: 'NORMAL' }],
  { id: 1, tier: 'NORMAL' },
  options,
);
// [{ id: 1, tier: 'NORMAL' }, { id: 3, tier: 'NORMAL' }]

Built-in two-tier helpers

If your items look like { id: number, priority: 0 | 1 }, use the ready-made helpers:

import {
  insertIdentifiedItem,
  reinsertIdentifiedItem,
  PriorityRank,
} from '@surihoney/priority-queue';

// PriorityRank.high === 0
// PriorityRank.normal === 1

API summary

| Export | Description | |--------|-------------| | insertItem(queue, item, options) | Add a new item to the queue | | reinsertItem(queue, item, options) | Put a returning item back in its fair position | | insertIdentifiedItem / reinsertIdentifiedItem | Same as above, for { id, priority } items | | PriorityRank | { high: 0, normal: 1 } | | PriorityQueueOptions | Type for { getPriorityRank, compareId? } |

All functions are immutable — they return a new array and do not change the one you pass in.

Development

npm install
npm test
npm run build

License

MIT