UNPKG

handsontable

Version:

Handsontable is a JavaScript Data Grid available for React, Angular and Vue.

62 lines (57 loc) 1.07 kB
import "core-js/modules/es.array.push.js"; /** * @class Stack * @util */ class Stack { constructor() { let initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; /** * Items collection. * * @type {Array} */ this.items = initial; } /** * Add new item or items at the back of the stack. * * @param {*} items An item to add. */ push() { this.items.push(...arguments); } /** * Remove the last element from the stack and returns it. * * @returns {*} */ pop() { return this.items.pop(); } /** * Return the last element from the stack (without modification stack). * * @returns {*} */ peek() { return this.isEmpty() ? undefined : this.items[this.items.length - 1]; } /** * Check if the stack is empty. * * @returns {boolean} */ isEmpty() { return !this.size(); } /** * Return number of elements in the stack. * * @returns {number} */ size() { return this.items.length; } } export default Stack;