Skip to content
shwibi edited this page Jun 18, 2021 · 1 revision

Stack

Stack is a better collection system for all your items! Well, kind of. It's basically a push to the top and pop from the top type of thing.

new Stack(name?, expectedItems?)

Create a new stack using a constructor:

const { Stack } = require("shwi-js");
new Stack("My stack");

Optionally, you can pass in an array of expected items in the stack:

new Stack("Error Stack", [Err, Error]);

Stack#push(item)

Push an item to the top of the stack!

const stack = new Stack();
stack.push("Top!");
// The top becomes "Top!"
stack.push("New top!");
// The top now becomes "New top!"

To get the top item you can use the Stack#topItem property (get method).

Stack#topItem

Gets the top item in the stack.

const myStack = new Stack();
myStack.push(1);
myStack.push(4);
myStack.push("A string?!");
const top = myStack.topItem;
// top will be "A string?!"

Stack#pop()

Pop the top item off of the stack and return it!

Stack#item(index?, item?, returnItemType?)

Get an item from the stack, or replace an item. The index is the index of the stack item. If an item is provided, it will replace the item and return on the basis of the returnItemType provided.

Return item types:

Value Returns
1 New item at the index
2 Previous item at that index
3 Return an object of both

The value type 3 returns an object that has the properties newItem and previousItem

v1.1.1

Updates

Feel free to open an Issue if you find anything wrong in the module! Or open a new Discussion if you have any suggestions, or just want to give a feedback!

Notes

The latest STABLE version is v1.0.0 with the addition of Physics* (depracated from v1.1.0^).

: v1.1.1 Fixed README
: v1.1.0 Released new Physics
: v0.0.5-beta.2 Released something
: v0.0.5-beta Released, countdown docs
: v0.0.4 Released
: v0.0.4-alpha.6 fix parser
: v0.0.4-alpha.5 npm update
: v0.0.4-alpha.4 (No additions except documentation edits)
: v0.0.4-alpha.2 Added tank, props, and functions.
: v0.0.4-alpha.1 has nothing new in it, it is just fixation of documentation on npm

Clone this wiki locally