historyarray
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

A type of array for storing states of history.

Note that you are only expected to pull items out of history, never look at the 'current' one.

TypeScript definitions are included.

Usage

const { HistoryArray } = require("historyarray");

const SIZE = 5;
const OPTIONAL_INITIAL = "One";
const arr = new HistoryArray(SIZE, OPTIONAL_INITIAL);
arr.push("Two");
arr.push("Three");
arr.push("Four");
arr.push("Five");
arr.push("Six");
console.log(arr.forward()); // === null;  nothing newer than the newest
console.log(arr.back()); //    === "Five";
console.log(arr.forward()); // === "Six"; can go back and forth
arr.back(); arr.back();
arr.push("NewFive"); //                   kills history in front
console.log(arr.forward()); // === null;
arr.back(); arr.back();
console.log(arr.back()); //    === "Two";
console.log(arr.back()); //    === null;  mustn't wrap around

Readme

Keywords

none

Package Sidebar

Install

npm i historyarray

Weekly Downloads

0

Version

1.1.1

License

WTFPL

Unpacked Size

17.6 kB

Total Files

9

Last publish

Collaborators

  • nixxquality