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 🙏

© 2024 – Pkg Stats / Ryan Hefner

progress-monitor

v1.0.0

Published

Splittable progress monitor for node.js, inspired by Eclipse IProgressMonitor and SubMonitor.

Downloads

2

Readme

progress-monitor

Splittable progress monitor for node.js, inspired by Eclipse IProgressMonitor and SubMonitor. Extends EventEmitter to provide a simple API. The goal is to provide easy to use progress monitoring across different parts of a program without those parts needing to know about how much work there is.

Still in progress! The API is not stable, please specify a specific version in your package.json if you want to use this!

Installation

npm install x

Usage

  • At the start of a method call adjustTotal().
  • Whenever you want to call a new method, use split() to create a new child monitor.
const ProgressMonitor = require("progress-monitor");

//create new monitor
var monitor = new ProgressMonitor(100);

//create submonitor for 50/100 work of monitor
var subMonitor1 = monitor.split(50);
//do some work in another function
work(subMonitor1);

//do rest of work
monitor.work(50);

//report end of work
monitor.emit("end");

/**
 * Preforms some work.
 */
function work(monitor) {
  //adjust the total, this way functions don't need to know the original amount of work
  var subMonitor = ProgressMonitor.adjustTotal(monitor, 100);

  //do the work
  for (var i = 0; i < 100; i++) {
    subMonitor.emit("work", 1);
  }

  //report end of work
  subMonitor.emit("end");

  return;
}

constructor(total : number)

Create a new progress monitor with total amount of work.

const ProgressMonitor = require("progress-monitor");

var monitor = new ProgressMonitor(100);

ProgressMonitor.adjustTotal(monitor: ProgressMonitor, newTotal : number)

Static function to adjust the total of a passed monitor to newTotal. Returns the monitor after scaling. Returns null if the monitor has already begun/has children.

const ProgressMonitor = require("progress-monitor");

var monitor = new ProgressMonitor(); //default 100
monitor = ProgressMonitor.adjustTotal(monitor, 10);

split(total: number)

Create a new child monitor that will work for total of parent's work. In the following example, a submonitor is made for 50 out of 100 of the parent's work. When the child is done it will have consumed 50 of the 100 work. The child will be initialized with a total work of 50, you can use adjustTotal to scale this back to 100, but it will still account for the same percentage as the parent.

const ProgressMonitor = require("progress-monitor");

var monitor = new ProgressMonitor(100);
var subMonitor = monitor.split(50);

Events

Emit and handle start, work and end events using the EventEmitter API.

start()

monitor.on("start", function () {
  console.log("STARTING...");
});
monitor.emit("start");

work(value)

//work event, print percentage every 10%
var toPrint = 10;
var buffer = 0;
monitor.on("work", function (value) {
  buffer += value;
  if (buffer >= 10) {
    buffer = 0;
    console.log(toPrint + "%");
    toPrint += 10;
  }
});

monitor.emit("work");

end()

//end event
monitor.on("end", function () {
  console.log("DONE!");
});

monitor.emit("end");

TO-DO

  • I don't know if the events should be wrapped with functions, I wrote this quickly and I kind of like using the EventEmitter API.
  • Add tests