Created
October 15, 2021 09:28
-
-
Save DarrenOfficial/f33cc9b75f7f9af8663b78c268bc1f00 to your computer and use it in GitHub Desktop.
big circle yes
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
| /** | |
| * Create a text progress bar | |
| * @param {Number} value - The value to fill the bar | |
| * @param {Number} maxValue - The max value of the bar | |
| * @param {Number} size - The bar size (in letters) | |
| * @return {{Bar: string, percentageText: string}} - The bar | |
| */ | |
| module.exports = (value, maxValue, size) => { | |
| const percentage = value / maxValue; // Calculate the percentage of the bar | |
| const progress = Math.round(size * percentage); // Calculate the number of square caracters to fill the progress side. | |
| const emptyProgress = size - progress; // Calculate the number of dash caracters to fill the empty progress side. | |
| const progressText = "—".repeat(progress); // Repeat is creating a string with progress * caracters in it | |
| const emptyProgressText = "—".repeat(emptyProgress); // Repeat is creating a string with empty progress * caracters in it | |
| const percentageText = Math.round(percentage * 100) + "%"; // Displaying the percentage of the bar | |
| const Bar = progressText + "⚪" + emptyProgressText; // Creating the bar | |
| return { Bar, percentageText }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment