Registry / storage / queue-adt

queue-adt

JSON →
library0.1.1jsnpmunverified

A lightweight FIFO queue data structure implementation for browser and Node.js. Version 0.1.1 provides enqueue, dequeue, first, isEmpty, size, empty methods and an iterator. Supports bounded capacity with optional initial capacity. Minimal dependencies, simple API. No TypeScript types. Suitable for small projects needing a basic queue.

npm install queue-adt
INSTALL
IMPORT
SIG · QUEUE-ADT
Q
queue-adt
storagejavascriptv0.1.1
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
const Queue = require('queue-adt');
const { Queue } = require('queue-adt');
The library exports a single constructor function as default via CommonJS. Named import will be undefined.
Queue
import Queue from 'queue-adt';
import { Queue } from 'queue-adt';
ESM imports must use default import syntax. Named import will result in undefined.
Queue
<script src="queue-adt.min.js"></script>; var queue = new Queue();
var Queue = require('queue-adt'); (in browser without bundler)
Browser script tag exposes global Queue constructor. Do not use require() in plain browser environment.

Shows basic Queue operations: enqueue, first, isEmpty, size, dequeue, iterator, and empty.

const Queue = require('queue-adt'); const queue = new Queue(); queue.enqueue(10); queue.enqueue('foo'); queue.enqueue({hello: 'world'}); console.log(queue.first().hello); // 'world' console.log(queue.isEmpty()); // false console.log(queue.size()); // 3 queue.dequeue(); console.log(queue.size()); // 2 const itr = queue.iterator; while(itr.hasNext()) { console.log(itr.next()); } queue.empty(); console.log(queue.isEmpty()); // true
Debug
Known issues
gotchaqueue.dequeue() returns the removed element, not the new size.
fix
Assign result to a variable: const item = queue.dequeue();
affects: >=0.1.0
gotchaqueue.enqueue() returns the new size of the queue, not undefined.
fix
Do not assume enqueue returns nothing; use return value if needed.
affects: >=0.1.0
gotchaQueue constructor can throw if initialCapacity is negative or non-integer.
fix
Pass only non-negative integers: new Queue(10);
affects: >=0.1.0
gotchaqueue.iterator is a property, not a method. Access without parentheses.
fix
Use queue.iterator (not queue.iterator()).
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: queue.iterator is not a function
Caused by calling iterator() as a method instead of accessing as property.
fix
Use queue.iterator (no parentheses) to get the iterator object.
Uncaught TypeError: queue.first is not a function
Possibly using an older version that used a different method name. Alternatively, queue is empty and first() was called before enqueue.
fix
Ensure queue exists and has elements before calling first(). Check version.
Error: Queue is full
Enqueuing beyond the initial capacity when a limited capacity Queue was created.
fix
Use new Queue() without arguments for infinite capacity, or increase initialCapacity.
require() of ES Module not supported
The package uses CommonJS, but if you are using ESM, require() will not work in some environments.
fix
Use import Queue from 'queue-adt' in ESM context, or use a bundler that handles CommonJS.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
26
Amazon
1
OpenAI (training)
1
Resources
queue-adt — npm install queue-adt · libregistry