diff --git a/lib/node-progress.js b/lib/node-progress.js index 8eb0740..400be28 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -53,6 +53,9 @@ function ProgressBar(fmt, options) { options = options || {}; if ('string' != typeof fmt) throw new Error('format required'); if ('number' != typeof options.total) throw new Error('total required'); + if (options.curr % 1 !== 0 || options.curr < 0 || options.curr >= options.total) { + throw new Error('current required nature number and is less than or equal to total'); + } } this.fmt = fmt; @@ -70,6 +73,10 @@ function ProgressBar(fmt, options) { this.callback = options.callback || function () {}; this.tokens = {}; this.lastDraw = ''; + // start time for eta + if (this.curr >= 0 && this.curr <= this.total) { + this.start = new Date; + } } /** @@ -88,9 +95,6 @@ ProgressBar.prototype.tick = function(len, tokens){ if ('object' == typeof len) tokens = len, len = 1; if (tokens) this.tokens = tokens; - // start time for eta - if (0 == this.curr) this.start = new Date; - this.curr += len // try to render