UNPKG

@contextjs/collections

Version:

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

25 lines (24 loc) 522 B
export class Stack { stack = []; push(item) { this.stack.push(item); } pop() { return this.stack.length > 0 ? this.stack.pop() ?? null : null; } get current() { return this.stack.length > 0 ? this.stack[this.stack.length - 1] : null; } clear() { this.stack.length = 0; } get count() { return this.stack.length; } toArray() { return this.stack.slice(); } get isEmpty() { return this.stack.length === 0; } }