UNPKG

@contextjs/collections

Version:

Strongly-typed collection classes for TypeScript, including List, Dictionary, Queue, Stack, and HashSet.

25 lines (24 loc) 508 B
export class Queue { items = []; enqueue(item) { this.items.push(item); } dequeue() { return this.items.length > 0 ? this.items.shift() ?? null : null; } get peek() { return this.items.length > 0 ? this.items[0] : null; } get count() { return this.items.length; } get isEmpty() { return this.items.length === 0; } clear() { this.items.length = 0; } toArray() { return this.items.slice(); } }