TypeScript TQDM Progress Bar

0.8.6 · active · verified Sun Apr 19

ts-tqdm is a Node.js utility library that provides a progress bar functionality, directly inspired by the popular Python `tqdm` library. It allows developers to easily instrument loops, whether iterating over arrays or a fixed number of iterations, with visual progress feedback in the console. The current stable version is 0.8.6. As a focused utility, its release cadence is typically driven by feature enhancements or bug fixes. Its primary differentiator lies in its TypeScript-first design, ensuring type safety and excellent developer experience for TypeScript projects, while replicating the simple, intuitive API familiar to users of `tqdm` in other ecosystems. It is best suited for command-line applications and scripts where visual progress indication can significantly improve user experience for long-running operations.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates `tqdm` usage for both fixed iterations and array iteration, with asynchronous tasks.

import { tqdm } from "ts-tqdm";

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
    console.log('Starting long process...');
    const totalIterations = 50;

    // Iterate over a fixed number of iterations
    for (let i of tqdm(totalIterations, { description: 'Processing items' })) {
        // Simulate an asynchronous task
        await delay(50);
        if (i % 10 === 0) {
            // console.log(`  Processed item ${i}`); // Avoid console.log inside tqdm loop if it interferes with progress bar
        }
    }

    console.log('Finished processing items.\n');

    const data = Array.from({ length: 25 }, (_, i) => `item-${i}`);
    for (let item of tqdm(data, { description: 'Analyzing data' })) {
        await delay(100);
        // console.log(`  Analyzing ${item}`);
    }
    console.log('Data analysis complete.');
})();

view raw JSON →