console-progress-bar
Advanced tools
Comparing version 0.0.4 to 0.1.0
26
app.js
@@ -0,1 +1,4 @@ | ||
// Import. | ||
const CColor = require('ccolor'); | ||
// Constants. | ||
@@ -39,4 +42,4 @@ const ENCODING = 'utf8'; | ||
this.value = 0; | ||
this.percent = 0; | ||
this.filledParts = 0; | ||
this.percent = -1; | ||
this.filledParts = -1; | ||
this.maxValue = progressBarOptions.maxValue; | ||
@@ -72,4 +75,5 @@ this.startChars = progressBarOptions.startChars; | ||
const progressBarString = `${this.startChars}${filledPartsCharsString}${notFilledPartCharsString}${this.endChars}`; | ||
const progressBarStringWithColor = addColor(progressBarString, this.percent); | ||
const newLineIfLast = this.percent === 100 ? '\n' : ''; | ||
process.stdout.write(`\r${progressBarString}${newLineIfLast}`); | ||
process.stdout.write(`\r${progressBarStringWithColor}${newLineIfLast}`); | ||
} | ||
@@ -117,3 +121,19 @@ | ||
/** | ||
* Add color. | ||
* @param {string} progressBarString - Progress bar string. | ||
* @param {number} percent - Percent. | ||
* @return {string} | ||
*/ | ||
function addColor(progressBarString, percent) { | ||
// Set color accordance to percent value. | ||
switch (percent) { | ||
case 100: | ||
return CColor.green(progressBarString); | ||
default: | ||
return CColor.yellow(progressBarString); | ||
} | ||
} | ||
// Export. | ||
module.exports = ConsoleProgressBar; |
{ | ||
"name": "console-progress-bar", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Console progress bar", | ||
@@ -24,3 +24,6 @@ "main": "app.js", | ||
}, | ||
"homepage": "https://gitlab.com/vsichka/console-progress-bar.npm#README" | ||
"homepage": "https://gitlab.com/vsichka/console-progress-bar.npm#README", | ||
"dependencies": { | ||
"ccolor": "^1.0.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6410
131
1
+ Addedccolor@^1.0.0
+ Addedccolor@1.3.1(transitive)