forked from visionmedia/node-progress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: modified
:total
type to positive integer
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
Showing
1 changed file
with
6 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
/*! | ||
* node-progress | ||
* Copyright(c) 2011 TJ Holowaychuk <[email protected]> | ||
|
@@ -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.
Sorry, something went wrong. |
||
|
||
this.fmt = fmt; | ||
this.curr = options.curr || 0; | ||
|
@@ -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); | ||
|
end s?