Skip to content

Commit c360a66

Browse files
authored
Merge pull request #4 from andre487/add-description
Add description
2 parents cdf068f + b462666 commit c360a66

File tree

4 files changed

+98
-96
lines changed

4 files changed

+98
-96
lines changed

README.md

Lines changed: 83 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# TQDM-like progress bar for Node.js console applications
22

3-
```
4-
node-console-progress-bar-tqdm
5-
```
3+
Full name: `node-console-progress-bar-tqdm`
64

75
[![Test commit](https://github.com/andre487/node-console-progress-bar-tqdm/actions/workflows/test-commit.yml/badge.svg)](https://github.com/andre487/node-console-progress-bar-tqdm/actions/workflows/test-commit.yml)
86
[![Downloads](https://img.shields.io/npm/dm/node-console-progress-bar-tqdm.svg?style=flat-square)](https://www.npmjs.com/package/node-console-progress-bar-tqdm)
@@ -23,9 +21,9 @@ Tested on Linux, macOS and Windows.
2321
## Table of contents
2422

2523
* [How does it look?](#how-does-it-look)
26-
* [Quick reference](#quick-reference)
2724
* [Quick examples](#quick-examples)
2825
* [Installation](#installation)
26+
* [Quick reference](#quick-reference)
2927
* [Examples](#examples)
3028

3129
## How does it look?
@@ -34,11 +32,81 @@ Tested on Linux, macOS and Windows.
3432
50% |████████████████████████████████████████████████ | 50/100 [00:01.630<00:01.630, 0.033s/it]
3533
```
3634

35+
https://github.com/andre487/node-console-progress-bar-tqdm/assets/1009104/afac1fe2-da92-433f-8791-4754f736feab
36+
37+
## Quick examples
3738

39+
```ts
40+
import {tqdm, TqdmProgress} from 'node-console-progress-bar-tqdm';
3841

39-
https://github.com/andre487/node-console-progress-bar-tqdm/assets/1009104/afac1fe2-da92-433f-8791-4754f736feab
42+
// Array as Iterable with length
43+
for (const item: number of tqdm([1, 2, 3, 4, 5])) {
44+
doSomeWorkOn(item);
45+
}
46+
47+
// Number generates range
48+
for (const idx: number of tqdm(100_000)) {
49+
doSomeWorkOn(idx);
50+
}
4051

52+
// Generator as Iterable without length
53+
const inp1: Generator<Item> = itemGenerator();
54+
for (const item: Item of tqdm(inp1)) {
55+
doSomeWorkOn(item);
56+
}
4157

58+
// AsyncGenerator as AsyncIterable
59+
const inp2: AsyncGenerator<Item> = itemAsyncGenerator();
60+
for await (const item: Item of tqdm(inp2, {total: 100})) {
61+
doSomeWorkOn(item);
62+
}
63+
64+
// Progress bar without using in a loop directly
65+
const pb = new TqdmProgress({
66+
total: items.length,
67+
progressColor: '#f1d3c4',
68+
});
69+
// render the empty progress bar
70+
pb.render();
71+
items.forEach((item) => {
72+
doSomeWorkOn(item);
73+
// update progress bar by 1 item
74+
progressBar.update();
75+
});
76+
// force render for printing delayed symbols and other finalization (not required)
77+
pb.close();
78+
79+
// Progress bar without using in a loop but with suitable wrapper with automatic opening and closing
80+
const res1 = TqdmProgress.withProgress((progressBar) => {
81+
return items.map((item) => {
82+
const res = doSomeWorkOn(item);
83+
// update progress bar by 1 item
84+
progressBar.update();
85+
return res;
86+
});
87+
}, {total: items.length, progressColor: '$128'});
88+
handleResult(res1);
89+
90+
// An async version of the previous case
91+
const res2 = await TqdmProgress.withAsyncProgress(async (progressBar) => {
92+
const res: HandledItem[] = [];
93+
for await (const item of getAsyncItems()) {
94+
res.push(await doSomeWorkOn(item));
95+
// update progress bar by 1 item
96+
progressBar.update();
97+
}
98+
return res;
99+
}, {total: estimateItemsCount(), progressColor: '$200'});
100+
handleResult(res2);
101+
```
102+
103+
## Installation
104+
105+
```shell
106+
npm install --save node-console-progress-bar-tqdm
107+
yarn add node-console-progress-bar-tqdm
108+
pnpm install node-console-progress-bar-tqdm
109+
```
42110
43111
## Quick reference
44112
@@ -151,80 +219,6 @@ export declare class TqdmProgress implements ITqdmProgress {
151219
}
152220
```
153221
154-
## Quick examples
155-
156-
```ts
157-
import {tqdm, TqdmProgress} from 'node-console-progress-bar-tqdm';
158-
159-
// Array as Iterable with length
160-
for (const item: number of tqdm([1, 2, 3, 4, 5])) {
161-
doSomeWorkOn(item);
162-
}
163-
164-
// Number generates range
165-
for (const idx: number of tqdm(100_000)) {
166-
doSomeWorkOn(idx);
167-
}
168-
169-
// Generator as Iterable without length
170-
const inp1: Generator<Item> = itemGenerator();
171-
for (const item: Item of tqdm(inp1)) {
172-
doSomeWorkOn(item);
173-
}
174-
175-
// AsyncGenerator as AsyncIterable
176-
const inp2: AsyncGenerator<Item> = itemAsyncGenerator();
177-
for await (const item: Item of tqdm(inp2, {total: 100})) {
178-
doSomeWorkOn(item);
179-
}
180-
181-
// Progress bar without using in a loop directly
182-
const pb = new TqdmProgress({
183-
total: items.length,
184-
progressColor: '#f1d3c4',
185-
});
186-
// render the empty progress bar
187-
pb.render();
188-
items.forEach((item) => {
189-
doSomeWorkOn(item);
190-
// update progress bar by 1 item
191-
progressBar.update();
192-
});
193-
// force render for printing delayed symbols and other finalization (not required)
194-
pb.close();
195-
196-
// Progress bar without using in a loop but with suitable wrapper with automatic opening and closing
197-
const res1 = TqdmProgress.withProgress((progressBar) => {
198-
return items.map((item) => {
199-
const res = doSomeWorkOn(item);
200-
// update progress bar by 1 item
201-
progressBar.update();
202-
return res;
203-
});
204-
}, {total: items.length, progressColor: '$128'});
205-
handleResult(res1);
206-
207-
// An async version of the previous case
208-
const res2 = await TqdmProgress.withAsyncProgress(async (progressBar) => {
209-
const res: HandledItem[] = [];
210-
for await (const item of getAsyncItems()) {
211-
res.push(await doSomeWorkOn(item));
212-
// update progress bar by 1 item
213-
progressBar.update();
214-
}
215-
return res;
216-
}, {total: estimateItemsCount(), progressColor: '$200'});
217-
handleResult(res2);
218-
```
219-
220-
## Installation
221-
222-
```shell
223-
npm install --save node-console-progress-bar-tqdm
224-
yarn add node-console-progress-bar-tqdm
225-
pnpm install node-console-progress-bar-tqdm
226-
```
227-
228222
## Examples
229223
230224
In these examples, besides the main goal, different input collections are illustrated
@@ -240,13 +234,13 @@ npm start
240234
241235
| File | Title | Description | Tags |
242236
| ---- | ----- | ----------- | ---- |
243-
| [basic.cjs](example/examples/basic.cjs) | Basic example | Iterate over an array without any options | `CJS`, `Array`, `defaults` |
244-
| [generator.mjs](example/examples/generator.mjs) | Generator examples | A couple of examples where we iterate over generator | `ESM`, `Generator`, `with/without total` |
245-
| [countdown.mjs](example/examples/countdown.mjs) | Countdown | Countdown, progress bar changes from full to empty | `ESM`, `Iterator`, `countdown` |
246-
| [unit-scaling.cjs](example/examples/unit-scaling.cjs) | Unit scaling, range iteration | Example with iteration over number range defined by `total` with unit scaling (k,M,G,T) | `CJS`, `Number`, `units`, `unit scaling` |
247-
| [custom-progress-bar.mts](example/examples/custom-progress-bar.mts) | Custom progress style | Fully customized progress bar written on TypeScript | `TS`, `Generator`, `units`, `color`, `styling`, `max width` |
248-
| [sync-iterator-input.mts](example/examples/sync-iterator-input.mts) | Iteration over sync iterator | Example with Iterator and Iterable as input | `TS`, `Iterable`, `color`, `styling` |
249-
| [async-iterator-input.mts](example/examples/async-iterator-input.mts) | Iteration over async iterator | Example with AsyncIterator and AsyncIterable as input | `TS`, `AsyncIterable`, `async`, `for/await`, `color`, `styling` |
250-
| [progress-with-no-iteration.cjs](example/examples/progress-with-no-iteration.cjs) | Using progress bar directly | There is no iteration over tqdm iterator, direct TqdmProgress usage. Progress split to 2 parts | `CJS`, `TqdmProgress`, `no tqdm()`, `flush output`, `resuming`, `color` |
251-
| [progress-with-no-iteration-ctx.mts](example/examples/progress-with-no-iteration-ctx.mts) | Using progress bar through context helpers | There is no tqdm function, using withProgress and withAsyncProgress helpers | `TS`, `TqdmProgress`, `withProgress`, `withAsyncProgress`, `no tqdm()`, `color`, `styling`, `emoji` |
252-
| [direct-iteration.mts](example/examples/direct-iteration.mts) | Direct usage of Tqdm class | Very advanced example with direct Tqdm usage | `TS`, `Generator`, `AsyncGenerator`, `async`, `async/await`, `no loop`, `units`, `color`, `styling` |
237+
| [basic.cjs](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/basic.cjs) | Basic example | Iterate over an array without any options | `CJS`, `Array`, `defaults` |
238+
| [generator.mjs](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/generator.mjs) | Generator examples | A couple of examples where we iterate over generator | `ESM`, `Generator`, `with/without total` |
239+
| [countdown.mjs](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/countdown.mjs) | Countdown | Countdown, progress bar changes from full to empty | `ESM`, `Iterator`, `countdown` |
240+
| [unit-scaling.cjs](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/unit-scaling.cjs) | Unit scaling, range iteration | Example with iteration over number range defined by `total` with unit scaling (k,M,G,T) | `CJS`, `Number`, `units`, `unit scaling` |
241+
| [custom-progress-bar.mts](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/custom-progress-bar.mts) | Custom progress style | Fully customized progress bar written on TypeScript | `TS`, `Generator`, `units`, `color`, `styling`, `max width` |
242+
| [sync-iterator-input.mts](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/sync-iterator-input.mts) | Iteration over sync iterator | Example with Iterator and Iterable as input | `TS`, `Iterable`, `color`, `styling` |
243+
| [async-iterator-input.mts](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/async-iterator-input.mts) | Iteration over async iterator | Example with AsyncIterator and AsyncIterable as input | `TS`, `AsyncIterable`, `async`, `for/await`, `color`, `styling` |
244+
| [progress-with-no-iteration.cjs](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/progress-with-no-iteration.cjs) | Using progress bar directly | There is no iteration over tqdm iterator, direct TqdmProgress usage. Progress split to 2 parts | `CJS`, `TqdmProgress`, `no tqdm()`, `flush output`, `resuming`, `color` |
245+
| [progress-with-no-iteration-ctx.mts](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/progress-with-no-iteration-ctx.mts) | Using progress bar through context helpers | There is no tqdm function, using withProgress and withAsyncProgress helpers | `TS`, `TqdmProgress`, `withProgress`, `withAsyncProgress`, `no tqdm()`, `color`, `styling`, `emoji` |
246+
| [direct-iteration.mts](https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/example/examples/direct-iteration.mts) | Direct usage of Tqdm class | Very advanced example with direct Tqdm usage | `TS`, `Generator`, `AsyncGenerator`, `async`, `async/await`, `no loop`, `units`, `color`, `styling` |

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "node-console-progress-bar-tqdm",
3-
"version": "1.0.0",
4-
"description": "",
3+
"version": "1.0.1",
54
"engines": {
65
"node": ">= 16"
76
},
@@ -31,8 +30,16 @@
3130
"readme:generate-examples": "node scripts/extract-examples.js",
3231
"prepare": "husky"
3332
},
34-
"keywords": [],
35-
"author": "",
33+
"keywords": [
34+
"nodejs",
35+
"cli",
36+
"progress-bar",
37+
"cli-app",
38+
"nodejs-cli",
39+
"tqdm"
40+
],
41+
"description": "Progress bar in console for Node.js in the style of TQDM Python library",
42+
"author": "andre487 <andrey.prokopyuk@gmail.com>",
3643
"license": "MIT",
3744
"devDependencies": {
3845
"@typescript-eslint/eslint-plugin": "7.0.2",

scripts/extract-examples.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ async function main() {
1919
}
2020
filePath = filePath.replace(/\\/g, '/');
2121
const baseName = path.basename(filePath);
22+
const fullUrl = `https://github.com/andre487/node-console-progress-bar-tqdm/blob/main/${filePath}`;
2223

2324
const tagString = tags.map((tag) => '`' + tag + '`').join(', ');
2425
console.log(
25-
`| [${baseName}](${filePath})`,
26+
`| [${baseName}](${fullUrl})`,
2627
`| ${title}`,
2728
`| ${description}`,
2829
`| ${tagString}`,

0 commit comments

Comments
 (0)