Registry / storage / elegant-queue

elegant-queue

JSON →
library1.0.9jsnpmunverified

elegant-queue (v1.0.9) is a high-performance queue implementation for JavaScript and TypeScript that uses a linked list of fixed-size arrays (circular buffers) to achieve O(1) enqueue and dequeue operations. Unlike native array-based queues that suffer from O(n) shifting, this package maintains constant-time operations even with millions of elements. It ships TypeScript definitions, supports both CommonJS and ES Modules, and offers a simple API: enqueue, dequeue, peek, clear, size, and isEmpty. The default internal array size is 4096, but can be configured. Suitable for Node.js and browser environments. Stable release, no recent updates.

npm install elegant-queue
INSTALL
IMPORT
SIG · ELEGANT-QUEUE
E
elegant-queue
storagejavascriptv1.0.9
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.

Queue
import { Queue } from 'elegant-queue'
import Queue from 'elegant-queue'
Queue is a named export, not a default export. Works with both ESM and CJS.
Queue (CommonJS)
const { Queue } = require('elegant-queue')
const Queue = require('elegant-queue')
CommonJS requires destructuring to get the named export.
Queue (TypeScript)
import { Queue } from 'elegant-queue'
import { Queue } from 'elegant-queue/src/index'
TypeScript types are bundled; no need for deep imports.

Demonstrates basic usage: creating a Queue, enqueue, dequeue, peek, size, isEmpty, and clear.

import { Queue } from 'elegant-queue'; // Create a queue (default buffer size 4096) const queue = new Queue<number>(); // Enqueue elements queue.enqueue(10); queue.enqueue(20); queue.enqueue(30); // Dequeue returns the first element (FIFO) const first = queue.dequeue(); console.log(first); // 10 // Peek without removing console.log(queue.peek()); // 20 // Check size console.log(queue.size()); // 2 // Check if empty console.log(queue.isEmpty()); // false // Clear all elements queue.clear(); console.log(queue.size()); // 0
Debug
Known issues
gotchaDequeue on empty queue throws EmptyQueueException
fix
Check queue.isEmpty() before calling dequeue(), or wrap in try-catch.
affects: >=1.0.0
gotchaPeek on empty queue throws EmptyQueueException
fix
Use isEmpty() before peek, or catch the exception.
affects: >=1.0.0
breakingQueue constructor accepts an optional arraySize (number) or an optional iterable (array) to initialize with data.
fix
When passing a single argument, if it's a number it sets buffer size; if it's an array it initializes the queue. Do not mix types.
affects: >=1.0.0
deprecatedThe package has no known deprecated APIs in current version.
fix
N/A
affects: none
Errors
Common errors & fixes
Error: EmptyQueueException
Calling dequeue() or peek() on an empty queue.
fix
Always call isEmpty() before dequeue/peek, or catch the exception.
TypeError: queue_1.Queue is not a constructor
Using default import instead of named import.
fix
Use import { Queue } from 'elegant-queue' instead of import Queue from 'elegant-queue'.
Cannot find module 'elegant-queue' or its corresponding type declarations.
Missing npm install or incorrect tsconfig paths.
fix
Run 'npm install elegant-queue' and ensure 'node_modules' is included in TypeScript resolution.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
32 hits · last 30 days
node
30
Amazon
1
Resources
elegant-queue — npm install elegant-queue · libregistry