rbx-object-stack
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ObjectStack

A Stack data structure which is formed by creating a singly linked-list on already existing objects. All you need to do is add a previousNode?: T field to your object you wish to use in the Stack.

See the index.d.ts file for documentation on each member and method.

Demo:

import ObjectStack from "rbx-object-stack";

interface Token {
	type: "a" | "b" | "c";
	previousNode?: Token;
}

const objectStack = new ObjectStack<Token>();

objectStack.push({ type: "b" });
objectStack.push({ type: "a" });
objectStack.push({ type: "c" });

objectStack.pop(); // { type: "c" }
objectStack.isEmpty(); // false

// iterates through the stack, from top to bottom
for (let token = objectStack.top; token; token = token.previousNode) {
	const x = token.type;
}

/rbx-object-stack/

    Package Sidebar

    Install

    npm i rbx-object-stack

    Weekly Downloads

    2

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    6.05 kB

    Total Files

    6

    Last publish

    Collaborators

    • validark