Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bvaughn/progress-estimator
Logs a progress bar and estimation for how long a Promise will take to complete
https://github.com/bvaughn/progress-estimator
Last synced: 1 day ago
JSON representation
Logs a progress bar and estimation for how long a Promise will take to complete
- Host: GitHub
- URL: https://github.com/bvaughn/progress-estimator
- Owner: bvaughn
- Created: 2018-11-24T21:01:38.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-17T19:08:07.000Z (over 1 year ago)
- Last Synced: 2024-12-04T20:57:22.833Z (9 days ago)
- Language: JavaScript
- Size: 139 KB
- Stars: 2,143
- Watchers: 15
- Forks: 49
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome - progress-estimator - Logs a progress bar and estimation for how long a Promise will take to complete (JavaScript)
- awesome-nodejs - progress-estimator - Logs a progress bar and estimation for how long a Promise will take to complete. ![](https://img.shields.io/github/stars/bvaughn/progress-estimator.svg?style=social&label=Star) (Repository / Command-line Utilities)
- awesome-github-star - progress-estimator
- awesome-loading-indicators - progress-estimator - Logs a progress bar and estimation for how long a Promise will take to complete. (JavaScript)
- awesome-list - progress-estimator
README
# progress-estimator
Logs a progress bar and estimation for how long a Promise will take to complete. This library tracks previous durations in order to provide more accurate estimates over time.
![Demo](https://user-images.githubusercontent.com/29597/48986949-474e2400-f0cf-11e8-86d7-d201f8ad8eca.gif)
### π [Become a sponsor](https://github.com/sponsors/bvaughn/) or β [Buy me a coffee](http://givebrian.coffee/)
## Installation
```shell
# use npm
npm install progress-estimator# use yarn
yarn add progress-estimator
```## Usage example
```js
const createLogger = require('progress-estimator');
const { join } = require('path');// All configuration keys are optional, but it's recommended to specify a storage location.
// Learn more about configuration options below.
const logger = createLogger({
storagePath: join(__dirname, '.progress-estimator'),
});async function run() {
await logger(promiseOne, "This is a promise");
await logger(
promiseTwo,
"This is another promise. I think it will take about 1 second",
{
estimate: 1000
}
);
}
```
## API### `createLogger(optionalConfiguration)`
This method is the default package export. It creates and configures a logger function (documented below). The following configuration options are supported. (They apply only to the logger instance that's returned.)
| name | type | Description |
| --- | --- | --- |
| `logFunction` | Function | Custom logging function. Defaults to [`log-update`](https://npmjs.com/package/log-update). Must define `.done()` and `.clear()` methods. |
| `spinner` | object | Which spinner from the [`cli-spinners`](https://npmjs.com/package/cli-spinners) package to use. Defaults to `dots`. |
| `storagePath` | string | Where to record durations between runs. Defaults to [`os.tmpdir()`](https://nodejs.org/api/os.html). |
| `theme` | object | Custom [`chalk`](https://npmjs.com/package/chalk) theme. Look to the [default theme](https://github.com/bvaughn/progress-estimator/blob/master/src/theme.js) for a list of required keys. |### `logger(promise, labelString, options)`
This method logs a progress bar and estimated duration for a promise. It requires at least two parametersβ a `Promise` and a label (e.g. "Running tests"). The label is SHA1 hashed in order to uniquely identify the promise.
An optional third parameter can be provided as well with the following keys:
| name | type | Description |
| --- | --- | --- |
| `estimate` | Number | Estimated duration of promise. (This value is used initially, until a history of actual durations have been recorded.) |
| `id` | String | Uniquely identifies the promise. This value is needed if the label string is not guaranteed to be unique. |