{"id":12189,"library":"ts-tqdm","title":"TypeScript TQDM Progress Bar","description":"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.","status":"active","version":"0.8.6","language":"javascript","source_language":"en","source_url":"https://github.com/delarco/ts-tqdm","tags":["javascript","tqdm","typescript","ts-tqdm","progress bar"],"install":[{"cmd":"npm install ts-tqdm","lang":"bash","label":"npm"},{"cmd":"yarn add ts-tqdm","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-tqdm","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ts-tqdm is primarily an ESM module and expects named imports. CommonJS `require` is not the recommended or natively supported way to import.","wrong":"const { tqdm } = require('ts-tqdm');","symbol":"tqdm","correct":"import { tqdm } from 'ts-tqdm';"},{"note":"The `tqdm` function is a named export, not a default export. Using a default import will result in `undefined`.","wrong":"import tqdm from 'ts-tqdm';","symbol":"tqdm","correct":"import { tqdm } from 'ts-tqdm';"}],"quickstart":{"code":"import { tqdm } from \"ts-tqdm\";\n\nconst delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));\n\n(async () => {\n    console.log('Starting long process...');\n    const totalIterations = 50;\n\n    // Iterate over a fixed number of iterations\n    for (let i of tqdm(totalIterations, { description: 'Processing items' })) {\n        // Simulate an asynchronous task\n        await delay(50);\n        if (i % 10 === 0) {\n            // console.log(`  Processed item ${i}`); // Avoid console.log inside tqdm loop if it interferes with progress bar\n        }\n    }\n\n    console.log('Finished processing items.\\n');\n\n    const data = Array.from({ length: 25 }, (_, i) => `item-${i}`);\n    for (let item of tqdm(data, { description: 'Analyzing data' })) {\n        await delay(100);\n        // console.log(`  Analyzing ${item}`);\n    }\n    console.log('Data analysis complete.');\n})();","lang":"typescript","description":"Demonstrates `tqdm` usage for both fixed iterations and array iteration, with asynchronous tasks."},"warnings":[{"fix":"Avoid `console.log` within the loop body. If logging is necessary, consider buffering messages and printing them after the loop, or using `tqdm`'s internal logging mechanisms if available (not currently in `ts-tqdm`), or redirecting logs to a file.","message":"Direct console logging (e.g., `console.log`) inside a `tqdm` loop can interfere with the progress bar's display, causing flickering or incorrect rendering. `tqdm` re-renders the line constantly.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Check `process.stdout.isTTY` before conditionally enabling `tqdm`. For non-TTY environments, simply iterate without wrapping in `tqdm` or use a different logging approach. The library will gracefully degrade to no output if no TTY is detected.","message":"When `ts-tqdm` is used in environments without a TTY (e.g., some CI/CD pipelines, background processes without a terminal attached), the progress bar might not render correctly or at all. It relies on terminal capabilities for dynamic updates.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use browser-specific progress bar libraries for front-end applications. `ts-tqdm` is designed for server-side or command-line Node.js scripts.","message":"The library primarily targets Node.js environments and assumes a standard console output. Using it in browser environments directly is not supported and will likely lead to errors related to Node.js-specific globals or console behaviors.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using `import { tqdm } from 'ts-tqdm';` for ESM modules. For older Node.js versions or specific configurations, ensure proper transpilation if using ES Modules.","cause":"Incorrect import statement, often trying to use a CommonJS `require` syntax or a default import when `tqdm` is a named export.","error":"TypeError: (0 , ts_tqdm__WEBPACK_IMPORTED_MODULE_0__.tqdm) is not a function"},{"fix":"Ensure the argument passed to `tqdm` is an `Iterable` (e.g., `Array`, `Set`, `Map`) or a `number`. For example, `tqdm([1, 2, 3])` or `tqdm(100)`.","cause":"The `tqdm` function expects either a number (for fixed iterations) or an `Iterable` (like an array or Set). Passing a non-iterable type or a non-number type will result in a TypeScript error.","error":"Argument of type 'string[]' is not assignable to parameter of type 'number | Iterable<unknown>'."}],"ecosystem":"npm"}