-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathprogress-bar.js
More file actions
23 lines (21 loc) · 911 Bytes
/
Copy pathprogress-bar.js
File metadata and controls
23 lines (21 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Creates a textual representation of a progress bar to embed in a message.
* @param {number} percent - The percent of the progress bar to fill. **It should be in decimal form - if it is greater than 1 it will be divided by 100.**
* @param {number} [characterCount=10] - The number of characters to use to display the progress bar
* @param {string} [emptyCharacter='▱'] - The character to use for the unfilled portion of the progress bar. Recommended to use the default or a zero-width space
* @returns {string} The string form of the progress bar
*/
export function createProgressBar(
percent,
characterCount = 10,
emptyCharacter = '▱'
) {
let value = percent;
if (percent > 1) {
value = percent / 100;
}
const fill = Math.round(value * characterCount);
return `[${'▰'.repeat(fill)}${emptyCharacter.repeat(
characterCount - fill
)}]`.slice(0, characterCount + 2);
}