Skip to content

Instantly share code, notes, and snippets.

@ali-master
Created October 28, 2025 13:46
Show Gist options
  • Save ali-master/69d30b584c1eb6d7118e3c2508ebef1c to your computer and use it in GitHub Desktop.
Save ali-master/69d30b584c1eb6d7118e3c2508ebef1c to your computer and use it in GitHub Desktop.
Javascript Generate visual progress bar using ASCII 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