2.2.6 • Published 1 year ago

@qntm-code/progress-logger v2.2.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@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:

ArgumentTypeDescription
totalnumberThe total number of items to process.
messagestringThe message to display before the progress bar.
bytesOptional booleanWhether the total is bytes. Will format output accordingly
averageTimeSampleSizeOptional numberThe number of items to use when calculating the average time per item. Defaults to 100.
preventOverwriteOptional booleanPrevent overwriting the previous log of the bar
logFunctionoptiona (...args) => voidProvide 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:

ArgumentTypeOptionalDescription
amountnumbertrueThe number of items that were just processed (not the total)
durationnumbertrueThe 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();
  })
==
}
2.2.1

1 year ago

2.2.0

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.5

1 year ago

2.2.4

1 year ago

2.2.6

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago