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

@qntm-code/progress-logger

v2.2.6

Published

Log progress and estimated time remaining to the console

Downloads

1,401

Readme

@qntm-code/progress-logger

A simple progress logger for Node.js that outputs progress and estimated time remaining to the console.

GitHub release Quality Gate Status

Installation

You can install via npm or yarn.

npm

npm install --save @qntm-code/progress-logger

yarn

yarn add @qntm-code/progress-logger

Usage

Constructor Arguments

First you must create a new instance of the ProgressLogger class. The constructor takes the following arguments:

| Argument | Type | Description | | --------------------- | --------------------------- | --------------------------------------------------------------------------------------- | | total | number | The total number of items to process. | | message | string | The message to display before the progress bar. | | bytes | Optional boolean | Whether the total is bytes. Will format output accordingly | | averageTimeSampleSize | Optional number | The number of items to use when calculating the average time per item. Defaults to 100. | | preventOverwrite | Optional boolean | Prevent overwriting the previous log of the bar | | logFunction | optiona (...args) => void | Provide a custom logging function |

Methods

tick

Call tick on the ProgressLogger to notify the progress bar that item(s) have been processed. This method takes the following arguments:

| Argument | Type | Optional | Description | | -------- | ------ | -------- | ------------------------------------------------------------ | | amount | number | true | The number of items that were just processed (not the total) | | duration | number | true | The time taken to process the current item(s). |

If you don't pass a time argument when calling tick, the average time will be calculated using the durations between each time tick is called. This is useful if you are processing items batches as multiple items may be being processed at the same time.

dispose

If you want to stop using the ProgressLogger due to an error in your process, you must call dispose on the ProgressLogger instance to ensure the progress logger is disposed and prevent a memory leak. The ProgressLogger will automatically dispose itself if it reaches 100%.

Example

import { ProgressLogger } from '@qntm-code/progress-logger';

async function someAsyncProcess(): Promise<void> {
  // Do something
}

async function main(): Promise<void> {
  const itemsToProcess = [
    /* Some data */
  ];
  const total = itemsToProcess.length;

  const logger = new ProgressLogger({
    total,
    message: 'Processing',
  });


  await asyncForEach(itemsToProcess, async item => {
    const startTime = performance.now();

    await someAsyncProcess(item);

    logger.tick();
  })
==
}