A TypeScript package for tracking history of values.
npm install @typescript-package/history
import {
History,
HistoryAppend,
HistoryCore,
HistoryPrepend,
} from '@typescript-package/history';
import { History } from '@typescript-package/history';
// Initialize.
const history = new class History<Type, Size extends number = number>
extends AbstractHistory<Type, Size>{}({value: 5, size: 5});
console.group(`History README.md`);
console.log(`set 10 - 35`);
history.set(10).set(15).set(20).set(25).set(30).set(35);
// [10, 15, 20, 25, 30], 35, []
console.log(history.undoHistory.get(), history.current, history.redoHistory.get());
// undo 35
console.log(`undo`, 35);
history.undo();
// [10, 15, 20, 25], 30, [35]
console.log(history.undoHistory.get(), history.current, history.redoHistory.get());
// undo 30
console.log(`undo`, 30);
history.undo();
// [10, 15, 20], 25, [30, 35]
console.log(history.undoHistory.get(), history.current, history.redoHistory.get());
// undo 25
console.log(`undo`, 25);
history.undo();
// [10, 15], 20, [25, 30, 35]
console.log(history.undoHistory.get(), history.current, history.redoHistory.get());
// undo 20
console.log(`undo`, 20);
history.undo();
// [10], 15, [20, 25, 30, 35]
console.log(history.undoHistory.get(), history.current, history.redoHistory.get());
// redo 20
console.log(`redo`, 20);
history.redo();
// [10, 15], 20, [25, 30, 35]
console.log(history.undoHistory.get(), history.current, history.redoHistory.get());
console.groupEnd();
import { HistoryAppend as AbstractHistoryAppend } from '@typescript-package/history';
export const historyAppend = new class HistoryAppend<Type = number, Size extends number = number>
extends AbstractHistoryAppend<Type, Size>{}();
// Add to the history.
console.log(`add`, 127, 227);
historyAppend.add(127).add(227);
console.log(historyAppend.get()); // [127, 227]
// Peek.
console.log(`peekLast()`, historyAppend.peekLast()); // Outputs: 127
console.log(`peekNext()`, historyAppend.peekNext()); // Outputs: 227
// Take from the history.
console.log(historyAppend.take()); // Outputs: 227
console.log(historyAppend.get()); // Outputs: [127]
The core class for history append and prepend.
import { HistoryPrepend as AbstractHistoryPrepend } from '@typescript-package/history';
export const historyPrepend = new class HistoryPrepend<Type = number, Size extends number = number>
extends AbstractHistoryPrepend<Type, Size>{}();
// Add to the history.
console.log(`add`, 127, 327, 227);
historyPrepend.add(127).add(327).add(227);
console.log(historyPrepend.get()); // [227, 327, 127]
// Peek.
console.log(`peekLast()`, historyPrepend.peekLast()); // Outputs: 127
console.log(`peekNext()`, historyPrepend.peekNext()); // Outputs: 227
// Take from the history.
console.log(historyPrepend.take()); // 227
console.log(historyPrepend.get()); // [327, 127]
Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.
Support via:
Thanks for your support!
By participating in this project, you agree to follow Code of Conduct.
Given a version number MAJOR.MINOR.PATCH, increment the:
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards-compatible manner, and
- PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
FAQ How should I deal with revisions in the 0.y.z initial development phase?
The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.
How do I know when to release 1.0.0?
If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.
MIT © typescript-package (license)
- @typescript-package/affix: A lightweight TypeScript library for the affix - prefix and suffix.
- @typescript-package/descriptor: A lightweight TypeScript library for property descriptor.
- @typescript-package/name: A lightweight TypeScript library for the name with prefix and suffix.
- @typescript-package/queue: A lightweight TypeScript library for managing various queue and stack structures.
- @typescript-package/property: A lightweight TypeScript package with features to handle object properties.
- @typescript-package/range: A lightweight TypeScript library for managing various types of ranges.
- @typescript-package/regexp: A lightweight TypeScript library for RegExp.
- @typescript-package/state: Simple state management for different types in TypeScript.