Skip to content

Commit

Permalink
Fix: modified :total type to positive integer
Browse files Browse the repository at this point in the history
The input `:total` value is float, but the output `:current` value is more than `:total` value. The input `:total` is nagative integer or zero, but the output rendering failed.

Closes visionmedia#177, visionmedia#166
  • Loading branch information
fredgan committed Dec 11, 2020
1 parent 0790207 commit fe51435
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/node-progress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*!
* node-progress
* Copyright(c) 2011 TJ Holowaychuk <[email protected]>
Expand Down Expand Up @@ -52,8 +53,10 @@ function ProgressBar(fmt, options) {
} else {
options = options || {};
if ('string' != typeof fmt) throw new Error('format required');
if ('number' != typeof options.total) throw new Error('total required');
}
if (options.total % 1 !== 0 || options.total <= 0) {
throw new Error('format required positive integer');
}
}s

This comment has been minimized.

Copy link
@cstur

cstur Dec 26, 2020

end s?


this.fmt = fmt;
this.curr = options.curr || 0;
Expand Down Expand Up @@ -154,7 +157,7 @@ ProgressBar.prototype.render = function (tokens, force) {
}

var width = Math.min(this.width, availableSpace);

width = Math.floor(width);
/* TODO: the following assumes the user has one ':bar' token */
completeLength = Math.round(width * ratio);
complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
Expand Down

0 comments on commit fe51435

Please sign in to comment.