edit-history
v1.0.1
Published
An implementation of a simple edit history class.
Downloads
11
Maintainers
Readme
edit-history
Manage your undo/redo operations with ease!
Highlights
- Supports TypeScript!
- Supports Node and browser
- Includes full JSDoc documentation
- Very lightweight!
- Contains tests
Installation
NodeJS
npm install edit-history --save
Browser
Import the script:
<script src="https://joker876.github.io/edit-history/edit-history.min.js">
And import the class from a global object:
new EditHistory(/* capacity */);
Usage
import EditHistory from 'edit-history';
Constructor
new EditHistory<T = any>(capacity: number);
EditHistory constructor takes the history's maximum capacity as its only argument. Capacity is optional, and defaults to 100
.
The type of the elements can also be specified explicitly. The default type is any
.
const history = new EditHistory(50);
// or with specified type
const history = new EditHistory<number>(50);
Members
size
- the amount of past changes in the history (changes that can be undone).undoAmount
- alias ofsize
.redoAmount
- the amount of future changes in the history (changes that can be redone).capacity
- the maximum number of elements that can be stored in the history. Exceeding this value will cause the elements to be overwritten when pushed.