Registry / storage / std-queue

std-queue

JSON →
library0.1.6jsnpmunverified

std-queue is an efficient FIFO queue for JavaScript/TypeScript that provides O(1) enqueue and dequeue operations. Version 0.1.6 is the latest stable release. Its key differentiator is an underlying linked list of subqueues (arrays of max size 1000) that avoids the O(n) shift cost of naive array-based queues and the memory overhead of pure linked lists. Designed for handling large amounts of data efficiently. The package ships TypeScript type definitions and has no external dependencies. It is actively maintained on GitHub.

npm install std-queue
INSTALL
IMPORT
SIG · STD-QUEUE
S
std-queue
storagejavascriptv0.1.6
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 'std-queue'
import { Queue } from 'std-queue'
Default export only; named import will return undefined.
Queue
const Queue = require('std-queue')
const { Queue } = require('std-queue')
CommonJS require returns the default export directly.
Queue (type)
import Queue from 'std-queue'; type QueueType = InstanceType<typeof Queue>
import type { Queue } from 'std-queue'
TypeScript types are bundled but there is no named type export; use InstanceType or typeof pattern.

Demonstrates creating a queue, adding elements in bulk with push(), peeking front and back, dequeuing with shift(), checking length, and clearing the queue.

import Queue from 'std-queue'; const queue = new Queue(); queue.push(1); queue.push(2); for (let i = 10; i < 10000; i++) { queue.push(i); } queue.push('Hello', 'World'); console.log(queue.peek()); // 1 console.log(queue.last()); // 'World' console.log(queue.shift()); // 1 console.log(queue.length); // 9993 queue.clear(); console.log(queue.shift()); // undefined
Debug
Known issues
gotchaQueue instances do not have Array-like iteration (e.g., for...of). Use shift() or clear() to process all elements.
fix
Iterate manually: while (queue.length) { process(queue.shift()); }
affects: >=0.0.0
gotchaThe queue does not support negative indices or slicing; only peek(), last(), shift(), and clear() are available for access.
fix
Use standard array methods after converting to an array if needed.
affects: >=0.0.0
gotchashift() returns undefined when queue is empty, not throw an error.
fix
Check queue.length before calling shift() if undefined is unacceptable.
affects: >=0.0.0
gotchaThe queue does not have a built-in toArray() method; you must manually drain the queue to collect elements.
fix
const arr = []; while (queue.length) arr.push(queue.shift());
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading '0')
Attempting to access an element from an empty queue (e.g., shift() returns undefined, but code expects an actual value).
fix
Check queue.length before calling shift() or ensure queue is not empty.
Property 'Queue' does not exist on type 'typeof import("std-queue")'
Using named import `import { Queue } from 'std-queue'` instead of default import.
fix
Use default import: `import Queue from 'std-queue'`.
Require is not defined in ES module scope
Using require() in an ES module (type: module or .mjs file).
fix
Use import syntax: `import Queue from 'std-queue'`.
Upgrade
Version history
0.1.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
28 hits · last 30 days
node
26
Resources
std-queue — npm install std-queue · libregistry