Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/spookyuser/web-console-progress-bar

A progress bar for the browser console.
https://github.com/spookyuser/web-console-progress-bar

progress-bar progress-bar-component progress-bars

Last synced: 18 days ago
JSON representation

A progress bar for the browser console.

Awesome Lists containing this project

README

        

# web-console-progress-bar

[![NPM Version](https://img.shields.io/npm/v/web-console-progress-bar.svg)](https://www.npmjs.com/package/web-console-progress-bar)

> A progress bar for the browser console.

## Install

```sh
npm install web-console-progress-bar
```

## Usage

```typescript
import { ConsoleProgressBar } from "web-console-progress-bar"

const progressBar = new ConsoleProgressBar(100)
progressBar.update(10)
//=> Progress: [██████░░░░░░░░░░░░] 10% ETA: XXs
```

or

```typescript
const progressBar = new ConsoleProgressBar(100)

for (let i = 0; i <= 100; i++) {
progressBar.update(i)
// Simulate some delay
await new Promise((resolve) => setTimeout(resolve, 100))
}
```

This will create a progress bar in the console that updates every 2 seconds (default `updateInterval`), and clears the console before each update (default `clearConsole`).

## API

### Constructor

```typescript
constructor(total: number, updateInterval?: number, clearConsole?: boolean)
```

Creates a new instance of `ConsoleProgressBar`.

- `total` (number): The total number of items to process.
- `updateInterval` (number, optional): The interval (in milliseconds) at which to update the progress bar. Default is 2000.
- `clearConsole` (boolean, optional): Indicates whether to clear the console before updating the progress bar. Default is true.

### Method: update

```typescript
update(currentValue: number): void
```

Updates the current value of the progress bar.

- `currentValue` (number): The current value.