Created
October 28, 2025 13:46
-
-
Save ali-master/69d30b584c1eb6d7118e3c2508ebef1c to your computer and use it in GitHub Desktop.
Javascript Generate visual progress bar using ASCII characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Generate visual progress bar using ASCII characters | |
| * | |
| * @param value - Current value | |
| * @param max - Maximum value | |
| * @param width - Width of the bar in characters (default: 25) | |
| * @returns ASCII progress bar string (`█` for filled, `░` for empty) | |
| * | |
| * @example | |
| * createProgressBar(75, 100, 20) // "███████████████░░░░░" | |
| * createProgressBar(0.5, 1, 10) // "█████░░░░░" | |
| */ | |
| export function createProgressBar(value: number, max: number, width = 25): string { | |
| const filled = Math.round((value / max) * width) | |
| const empty = width - filled | |
| return '█'.repeat(filled) + '░'.repeat(empty) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment