Registry / storage / queue-lit

queue-lit

JSON →
library3.2.2jsnpmunverified

A tiny, fast queue data structure for JavaScript/TypeScript (v3.2.2, updated 2024). Provides O(1) push/pop operations as an alternative to Array#shift() which is O(n). ESM-only, ships TypeScript declarations, no dependencies. Iterable, with push, pop, clear, and size. Ideal for high-frequency enqueue/dequeue patterns like breadth-first search or stream buffering.

npm install queue-lit
INSTALL
IMPORT
SIG · QUEUE-LIT
Q
queue-lit
storagejavascriptv3.2.2
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 'queue-lit'
const Queue = require('queue-lit')
The package is ESM-only. CommonJS require() will fail.
Queue
import { Queue } from 'queue-lit'
import Queue from 'queue-lit'
Queue is a named export, not default export.
Queue
type QueueInstance = InstanceType<typeof Queue>
import { QueueType } from 'queue-lit'
No separate type export; types are inferred from the class.

Creates a queue, pushes items, iterates, pops, clears, and shows size in TypeScript.

import { Queue } from 'queue-lit'; const queue = new Queue<number>(); queue.push(10); queue.push(20); queue.push(30); console.log('Size:', queue.size); // 3 for (const item of queue) { console.log(item); // 10, 20, 30 } console.log(queue.pop()); // 10 console.log(queue.pop()); // 20 console.log(queue.pop()); // 30 console.log(queue.pop()); // undefined (empty queue) queue.push(100); queue.clear(); console.log('Size after clear:', queue.size); // 0
Debug
Known issues
breakingqueue-lit is ESM-only, does not support CommonJS require().
fix
Use import instead of require(). Ensure your project is configured for ESM (e.g., type: module in package.json, .mjs extension, or Node >=18 with experimental modules).
affects: >=3.0.0
breakingVersion 3 removed the default export; Queue is now a named export.
fix
Change `import Queue from 'queue-lit'` to `import { Queue } from 'queue-lit'`.
affects: >=3.0.0
deprecatedThe static method .size is now a getter property in v3.
fix
Use `queue.size` instead of `Queue.size` or `queue.size()`.
affects: >=3.0.0
gotchaQueue.pop() returns undefined when the queue is empty, but does not throw.
fix
Check queue.size before popping or handle undefined return values.
affects: >=0.0.0
gotchaThe queue is iterable but not a full iterable iterator protocol (no .next() method directly).
fix
Use for...of or spread operator to iterate. Do not call .next() on the queue directly.
affects: >=0.0.0
gotchaThe package has no custom iterator return method, so early termination of iteration (break/return) may not properly clean up internal state.
fix
When breaking early, consider using queue.clear() if needed. Otherwise, no side effects expected.
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
Using CommonJS require() to load an ESM-only package.
fix
Replace `const { Queue } = require('queue-lit')` with `import { Queue } from 'queue-lit'` and ensure your project is ESM-compatible.
SyntaxError: The requested module 'queue-lit' does not provide an export named 'default'
Trying to default-import Queue which is now a named export.
fix
Use `import { Queue } from 'queue-lit'` instead of `import Queue from 'queue-lit'`.
TypeError: queue.pop is not a function
Calling .pop() on an uninitialized or incorrectly imported queue (e.g., imported Queue class but forgot to instantiate).
fix
Ensure you have created an instance: `const queue = new Queue();` and that you imported Queue correctly.
Type 'Queue<T>' is not assignable to type 'IterableIterator<T>'.
Assuming Queue implements the full Iterator protocol (has .next()) when it only implements Iterable.
fix
Use for...of, spread, or convert to array with Array.from(queue) instead of calling .next().
Upgrade
Version history
3.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
Amazon
1
Resources
queue-lit — npm install queue-lit · libregistry