UNPKG

@barchart/common-js

Version:
60 lines (59 loc) 1.39 kB
/** * A stack collection (supports LIFO operations). * * @public */ export default class Stack { /** * Adds an item to the stack. * * @public * @param {object} item * @returns {object} - The item added to the stack. */ public push(item: object): object; /** * Removes and returns an item from the stack. Throws if the stack is empty. * * @public * @returns {object} - The removed from the stack. */ public pop(): object; /** * Returns the next item in the stack (without removing it). Throws if the stack is empty. * * @public * @returns {object} - The item added to the stack. */ public peek(): object; /** * Returns true if the stack is empty; otherwise false. * * @public * @returns {boolean} */ public empty(): boolean; /** * Runs an action on each item in the stack. * * @public * @param {Function} action - The action to run. */ public scan(action: Function): void; /** * Outputs an array of the stack's items; without affecting the * stack's internal state; * * @public * @returns {Array} */ public toArray(): any[]; /** * Returns a string representation. * * @public * @returns {string} */ public toString(): string; #private; }