npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

unro

v4.3.0

Published

a simple undo/redo implimentation to speed up your work

Downloads

38

Readme

Unro.js

Timeline your user action by integrating undo/redo functionalities in your app.

yeap that's me! @yousef_neji

How to?

Pretty simple!

// EJS
import unro from "unro";

// CommonJS
const unro = require("unro");

Changing some properties/settings of the feature

  • Creating an instance to use
let stack = unro();
  • Expand the size of the stack
stack.expand(30);
// now the stack is able to contain a thirteen stack and navigate through them
  • Change the used algorithme, which could be:
    • clearpath : once you undo and push new stack the forward stacks will be removed.
    • insertion : once you undo and push new stack the new one will be inserted in front of the forward stacks.
    • lineare : once you push new stack it will be always added to the end of the stacks list.
stack.setAlgorithme('lineare');
  • Pushing normal stack:

function removeItem(elm, parent){
    // creating a new stack
    stack.push({
        undo: () => parent.append(elm),
        redo: () => elm.remove()
    },/* true - to disable auto execute stack */);
    // the stack will auto execute unless you passed `true`
}

// using .save and .load
let listOfFlowers = [];
function removeFlower(name){
    let i = listOfFlowers.findIndex(a => a == name );
    if(i != -1)
        stack.push({
            undo: function(){
                let [flower, idx] = this.load();
                arrInsert(listOfFlowers, flower, idx);
            },
            redo: function(){
                this.save([listOfFlowers.splice(i,1),i])
            }
        })
}
  • Canvas Stacking:

this feature allows you to stack canvas content automating the undo redo calls.

drawLine(ctx,x1,y1,x2,y2){
    stack.push(function(mk){
        mk.use(ctx); // the destination canvas in which content will be changed
        mk.register('undo'); // register the undo stack

        // do rendering code in here, will auto execute
        ctx.beginPath();
        ctx.moveTo(x1,y1);
        ctx.lineTo(x2,y2);
        ctx.stroke();
        ctx.closePath();

        mk.register('redo'); // register the redo stack
    });
}
  • bigPush

Make all executed .push inside a one stack!

stack.bigPush(function () {
  insects.forEach((insect) => {
    let ox = insect.x;
    let oy = insect.y;
    let nx = ox + rand(xvalue);
    let ny = oy + rand(yvalue);
    insect.x = nx; // supposedly a function that gives a random number between 0-value
    insect.y = ny;
    stack.push({
      undo: function () {
        insect.x = ox;
        insect.y = oy;
      },
      redo: function () {
        insect.x = nx;
        insect.y = ny;
      },
    });
  });
});
  • handlers

Introducing pre-defined handlers for stacks operations, this RAM-friendlyt functionality allows to write once the same repetitive call, and use multiple times as u want, the tweak is using different parameters each time.

var list = [];
stack.defineHandler({
  label: "addToArray",
  undo: function (params) {
    const { elm } = params;
    let idx = list.findIndex((a) => a.name === elm.name);
    if (idx != -1) list.splice(idx, 1);
  },
  redo: function (params) {
    const { elm, idx } = params;
    list.splice(idx, 0, elm); // a trick to insert element in an array
  },
});

buttonA.addEventListener("click", function () {
  let idx = list.push(elm) - 1;
  // --- usage ----
  stack.push("addToArray", { elm, idx });
  // now you'll be having a functional undo/redo stack
});
  • the real magic

undo redo ready for the job now, or you can also moveTo for quick navigation to certain stack.


// to undo
stack.undo();

// to redo
stack.undo();

// to go to a specific stack
stack.moveTo(4);
// this functions `out-of-range` for uknown stack index
// or `current` if requested stack is current one

// free stacks
stack.free();

// exports the stacks identified by their labels defined at the ".push" call!
stack.exportStackActions();
  • Acquiring Qway or other shortcut library

  • the pattern(second parameter) either accepts a or b:

    • a: ctrl+z => undo ctrl+y => redo
    • b: ctrl+z => undo ctrl+shift+z => redo
stack.acquire(qway, pattern);