Registry / serialization / queue-typescript

queue-typescript

JSON →
library1.0.1jsnpmunverified

queue-typescript is a minimalist TypeScript library that provides a generic queue data structure. Currently at version 1.0.1, it offers a stable and lightweight solution for managing queues in TypeScript and JavaScript projects. The library distinguishes itself by its full support for TypeScript generics, allowing developers to create type-safe queues for any data type, including primitive types, objects, or custom classes, ensuring compile-time type checking. It also adheres to both the JavaScript iterator and iterable protocols, enabling seamless integration with modern JavaScript features such as `for...of` loops, the spread operator (`...`), and array deconstruction. Internally, `queue-typescript` relies on the `linked-list-typescript` package for its underlying data storage, contributing to efficient enqueue and dequeue operations. This package focuses on core queue functionality, delivering a straightforward, performant, and type-safe queue implementation without unnecessary overhead or additional utilities. Given its singular purpose and stable API, a rapid release cadence is not expected.

serialization
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This is the standard ESM import for TypeScript projects.

import { Queue } from 'queue-typescript';

While CommonJS `require` works, modern TypeScript projects typically use ESM imports. The `Queue` class is a named export, not a default export.

const { Queue } = require('queue-typescript');

Always specify the generic type parameter (e.g., `<string>`) when declaring or instantiating a `Queue` to leverage TypeScript's type safety features fully.

let myQueue: Queue<string> = new Queue<string>();

This example demonstrates how to create, initialize, enqueue items into, and iterate through a generic TypeScript Queue, showcasing its iterable protocol support.

import { Queue } from 'queue-typescript'; // Create a new queue initialized with numbers let numberQueue = new Queue<number>(10, 20, 30); console.log('Initial queue length:', numberQueue.length); // Expected: 3 console.log('Front element:', numberQueue.front); // Expected: 10 // Enqueue new items numberQueue.enqueue(40); numberQueue.enqueue(50); console.log('Queue after enqueuing:', numberQueue.length); // Expected: 5 // Iterate through the queue using for...of console.log('Queue elements:'); for (const item of numberQueue) { console.log(item); } // Expected: 10, 20, 30, 40, 50 (each on a new line) // Deconstruct the queue const [first, second, ...rest] = numberQueue; console.log('First element (deconstructed):', first); // Expected: 10 console.log('Second element (deconstructed):', second); // Expected: 20 console.log('Remaining elements (deconstructed):', rest); // Expected: [30, 40, 50] (or similar array representation)
Debug
Known footguns
gotchaType Mismatch during Queue Initialization or Enqueuing: The `Queue` class uses generics for type safety. Attempting to initialize or enqueue values that do not match the specified generic type `T` will result in a TypeScript compilation error.
gotchaEmpty Queue Operations: Attempting to access `queue.front` on an empty queue will return `undefined`.
gotchaCommonJS (require) vs. ESM (import) Syntax: While the package README shows both `require` and `import` for `Queue`, modern TypeScript projects and Node.js environments increasingly favor ESM `import` statements. Using `require` might indicate an older project setup or specific configuration.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
8 hits · last 30 days
gptbot
4
ahrefsbot
3
script
1
Resources