├── README.md
├── LICENSE
└── ProgressBar.js
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ## Text-ProgressBar
6 | A simple Javascript code to easily create text progress bar for your discord bot.
7 | It also works with all kind of programs.
8 |
9 | ## How to use it
10 |
11 | ```javascript
12 | var progressbar = progressBar(value, maxValue, size);
13 | ```
14 |
15 | ## Example
16 | 
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 MΛX
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ProgressBar.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Create a text progress bar
3 | * @param {Number} value - The value to fill the bar
4 | * @param {Number} maxValue - The max value of the bar
5 | * @param {Number} size - The bar size (in letters)
6 | * @return {String} - The bar
7 | */
8 | global.progressBar = (value, maxValue, size) => {
9 | const percentage = value / maxValue; // Calculate the percentage of the bar
10 | const progress = Math.round((size * percentage)); // Calculate the number of square caracters to fill the progress side.
11 | const emptyProgress = size - progress; // Calculate the number of dash caracters to fill the empty progress side.
12 |
13 | const progressText = '▇'.repeat(progress); // Repeat is creating a string with progress * caracters in it
14 | const emptyProgressText = '—'.repeat(emptyProgress); // Repeat is creating a string with empty progress * caracters in it
15 | const percentageText = Math.round(percentage * 100) + '%'; // Displaying the percentage of the bar
16 |
17 | const bar = '```[' + progressText + emptyProgressText + ']' + percentageText + '```'; // Creating the bar
18 | return bar;
19 | };
20 |
--------------------------------------------------------------------------------