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

yoctoqueue2

v2.0.0

Published

Tiny queue data structure

Readme

yoctoqueue2

Tiny, efficient queue data structure for JavaScript and TypeScript

Use this package instead of an array when you need to do a lot of Array#push() and Array#shift() on large arrays. Unlike Array#shift() which has linear time complexity O(n), Queue#dequeue() has constant time complexity O(1), which makes a huge difference for large collections.

A queue is an ordered list where elements are inserted at the end and removed from the front (FIFO — first-in, first-out).

This implementation keeps references to both the first (_first) and last (_last) nodes internally to allow efficient enqueue and dequeue operations without iterating through the entire queue.

It can be used in CommonJS, ESM, and IIFE environments. When used as an IIFE, it exposes a global variable named yoctoqueue2.

Install

npm install yoctoqueue2

Usage

Node / ESM

import Queue from "yoctoqueue2";

const queue = new Queue<string>();

queue.enqueue("🦄");
queue.enqueue("🌈");

console.log(queue.size);
//=> 2

console.log(...queue);
//=> '🦄 🌈'

console.log(queue.dequeue());
//=> '🦄'

console.log(queue.dequeue());
//=> '🌈'

Browser (via script injection)

// Open browser console and run:
const s = document.createElement("script");
s.src =
  "https://cdn.jsdelivr.net/gh/maanimis/yoctoqueue2@main/dist/index.global.js";
s.onload = () => {
  console.log("✅ yoctoqueue2 loaded");

  // Create a new queue instance
  const queue = new yoctoqueue2.default();

  queue.enqueue("🦄");
  queue.enqueue("🌈");

  console.log(queue.size);
  //=> 2

  console.log(...queue);
  //=> '🦄 🌈'

  console.log(queue.dequeue());
  //=> '🦄'

  console.log(queue.dequeue());
  //=> '🌈'
};
document.head.appendChild(s);

API

queue = new Queue<ValueType>()

The instance is an Iterable, so you can iterate over it front to back with a for…of loop. Iterating does not remove items. If you want to consume and remove items at the same time, use drain().

You can also spread the queue into an array, e.g., [...queue], but avoid doing this on large queues frequently, as it copies all items.

.enqueue(value: ValueType)

Add a value to the end of the queue. Time complexity: O(1).

.dequeue(): ValueType | undefined

Remove and return the next value in the queue. Returns undefined if the queue is empty. Time complexity: O(1).

.peek(): ValueType | undefined

Get the next value in the queue without removing it. Returns undefined if the queue is empty.

.drain(): IterableIterator<ValueType | undefined>

Returns an iterator that removes items as you consume them. Useful for processing and emptying the queue at the same time.

.clear(): void

Remove all items from the queue.

.size: number

The number of items currently in the queue.

Related

  • quick-lru - Simple “Least Recently Used” (LRU) cache