ts-progress
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -7,3 +7,3 @@ 'use strict'; | ||
var progress = Progress.create({ total: items }); | ||
run(progress, withPattern); | ||
run(progress, withDone); | ||
} | ||
@@ -14,4 +14,27 @@ function withPattern() { | ||
} | ||
function withDone() { | ||
var progress = Progress.create({ total: items }); | ||
progress.done(); | ||
console.log(); | ||
withUpdate(); | ||
} | ||
function withUpdate() { | ||
var progress = Progress.create({ total: items }); | ||
var count = 0; | ||
var iv = setInterval(function () { | ||
count++; | ||
progress.update(); | ||
if (count == items * 2) { | ||
clearInterval(iv); | ||
console.log(); | ||
withPattern(); | ||
} | ||
}, interval); | ||
} | ||
function withPatternAndColors() { | ||
var progress = Progress.create({ total: items, pattern: 'Progress: {bar.white.cyan.25} | Elapsed: {elapsed.green} | Remaining: {remaining.blue} | {percent.magenta} | {current.red}/{total.yellow}' }); | ||
run(progress, withTilte); | ||
} | ||
function withTilte() { | ||
var progress = Progress.create({ total: items, pattern: 'Progress: {bar.white.cyan.25} | Elapsed: {elapsed.green} | Remaining: {remaining.blue} | {percent.magenta} | {current.red}/{total.yellow}', title: 'Doing some work' }); | ||
run(progress); | ||
@@ -18,0 +41,0 @@ } |
{ | ||
"name": "ts-progress", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Flexible node progress bar for Windows/macOS/Linux.", | ||
@@ -41,5 +41,5 @@ "main": "progress.js", | ||
"dependencies": { | ||
"charm": "^1.0.1" | ||
"charm": "^1.0.2" | ||
}, | ||
"devDependencies": "" | ||
} |
@@ -10,4 +10,4 @@ 'use strict'; | ||
function Progress(_total, pattern, _textColor, _title, _updateFrequency) { | ||
if (_updateFrequency === void 0) { _updateFrequency = 0; } | ||
var _this = this; | ||
if (_updateFrequency === void 0) { _updateFrequency = 0; } | ||
this._total = _total; | ||
@@ -146,6 +146,10 @@ this._textColor = _textColor; | ||
}; | ||
/** | ||
* Updates progress | ||
*/ | ||
Progress.prototype.update = function () { | ||
this._now = new Date().getTime(); | ||
charm.up(1).erase('line').write("\r"); | ||
if (this._current === this._total - 1) { | ||
if (this._current >= this._total - 1) { | ||
this._current = (this._total - 1); | ||
this.stop(); | ||
@@ -163,2 +167,11 @@ } | ||
}; | ||
/** | ||
* Finishes progress | ||
*/ | ||
Progress.prototype.done = function () { | ||
this._now = new Date().getTime(); | ||
charm.up(1).erase('line').write("\r"); | ||
this._current = (this._total - 1); | ||
this.stop(); | ||
}; | ||
Progress.prototype.skipStep = function () { | ||
@@ -179,4 +192,3 @@ if (this._updateFrequency == 0) | ||
exports.Progress = Progress; | ||
//export = Progress | ||
module.exports = Progress; | ||
//# sourceMappingURL=progress.js.map |
@@ -29,2 +29,15 @@ # ts-progress | ||
``` | ||
## API | ||
### create(options) | ||
Creates and returns new progress bar. | ||
### update() | ||
Updates progress. | ||
### done() | ||
Finishes progress regardless of progress stage. Optional. | ||
@@ -56,3 +69,3 @@ ## Options | ||
## Update frequency | ||
When set limits progress bar update rate. Used to limit refresh rate for quickly running tasks progress. | ||
When set limits progress bar update rate. Used to limit refresh rate for quickly running tasks. | ||
@@ -59,0 +72,0 @@ In the example below progress bar will only update every 150 milliseconds instead of updating 1000 times every millisecond. This will reduce resource allocation to progress bar. |
@@ -10,3 +10,11 @@ interface IProgressOptions{ | ||
interface Progress{ | ||
/** | ||
* Updates progress | ||
*/ | ||
update(); | ||
/** | ||
* Finishes progress | ||
*/ | ||
done(); | ||
} | ||
@@ -20,2 +28,3 @@ | ||
new (total: number, pattern?: string, textColor?: string, title?: string, updateFrequency?: number): Progress; | ||
/** | ||
@@ -22,0 +31,0 @@ * Creates new progress bar object |
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
14180
273
127
Updatedcharm@^1.0.2