
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
undo-history
Advanced tools
A js/ts library to implement undo and redo functionality, with a simple API, with no dependencies or framework requirements.
A js/ts library to implement undo and redo functionality, with a simple API, with no dependencies or framework requirements.
import { UndoHistory } from 'undo-history';
// set up a trivial class to represent our app's state
interface State { foo: string }
var state = {foo: "cats"};
// set up a new `History` object to track our state, with basic `getClone` and `setClone` methods
var history = new UndoHistory<State>(
// max undo depth
100,
// `getClone` callback to return a copy of the working object
() => { return { foo: state.foo } },
// `setClone` callback to overwrite into our working object (MUST read properties FROM the object it is sent)
(newState) => state.foo = newState.foo
);
history.record("Initial state"); // record and label our initial state
// perform some user action
history.foo = "dogs";
// record and label what we've just done
history.record("Changed cats to dogs");
history.undo();
// state.foo == "cats"
history.redo();
// state.foo == "dogs"
It's critical that your callbacks are coded correctly, so that getClone returns a new object, and the setClone doesn't modify the object it is sent. Whether that means a shallow or deep clone is deliberately left up to the user, since there is no one-size-fits-all solution to this. You could also have a totally separate type for containing history states.
If you have undone several actions, and then record a new user action, the history ahead (redos) will be automatically overwritten, as you'd expect undo operations to work in any program.
FAQs
A js/ts library to implement undo and redo functionality, with a simple API, with no dependencies or framework requirements.
We found that undo-history demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.