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

timeout-percentage

v1.0.8

Published

Similar to setTimeout, but with multiple intervals to report elapsed time.

Downloads

1,517

Readme

timeout-percentage

NPM NPM Downloads

Similar to setTimeout, but periodically reports what percentage of the time has elapsed.

For example, for a timeout value of 1000ms, you can set 10 intervals, each 100ms, where you get a callback which reports the elapsed time in percentage. This is useful for creating progress bars.

You can also cancel the timeout before it ends.

Update: Now it can be called multiple times in parallel to setup multiple parallel timeouts.

Install

npm i -s timeout-percentage

Usage

const tp = require("../lib/index.js");

function intervalCallback(percentage) {
  console.log(`${percentage}% done.`);
}

function intervalEndCallback() {
  console.log(`Interval finished!`);
}

let options = {
  intervalCallback: intervalCallback, // Will be called at each interval
  intervalEndCallback: intervalEndCallback, // Will be called at the end of the timeout
  totalTimeout: 1000, // Total timeout in ms
  numberOfIntervals: 10 // Number of intervals
};

tp().start(options);

/*
Output:

10% done.
20% done.
30% done.
40% done.
50% done.
60% done.
70% done.
80% done.
90% done.
100% done.
Interval finished!
*/

See test/test.js for more examples.

Cancelling the timer

You can cancel a timer that is still running:

let myTimer = tp().start(options);
tp().stop(myTimer);