Socket
Socket
Sign inDemoInstall

progress

Package Overview
Dependencies
0
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.4 to 1.1.5

LICENSE

77

History.md

@@ -0,42 +1,67 @@

### 1.1.5 / 2014-03-25
1.0.0 / 2013-06-18
==================
* updated documentation and various other repo maintenance
* updated makefile to run examples with `make`
* removed dependency on readline module
* remove .version
* >=. Closes #19
* Merge pull request #15 from davglass/readline-osx
* On OSX revert back to terminal hack to avoid a readline bug
### 1.1.4 / 2014-03-14
0.1.0 / 2012-09-19
==================
* now supports streams, for example output progress bar to stderr, while piping
stdout
* increases performance and flicker by remembering the last drawn progress bar
* Fixed logic bug that caused bar to jump one extra space at the end [davglass]
* Working with readline impl, even on Windows [davglass]
* Using readline instead of the \r hack [davglass]
### 1.1.3 / 2013-12-31
0.0.5 / 2012-08-07
==================
* fixes a bug where bar would bug when initializing
* allows to pass updated tokens when ticking or updating the bar
* fixes a bug where the bar would throw if skipping to far
### 1.1.2 / 2013-10-17
* lets you pass an `fmt` and a `total` instead of an options object
### 1.1.0 / 2013-09-18
* eta and elapsed tokens default to 0.0 instead of ?.?
* better JSDocs
* added back and forth example
* added method to update the progress bar to a specific percentage
* added an option to hide the bar on completion
### 1.0.1 / 2013-08-07
* on os x readline now works, reverting the terminal hack
### 1.0.0 / 2013-06-18
* remove .version
* merge pull request #15 from davglass/readline-osx
* on OSX revert back to terminal hack to avoid a readline bug
### 0.1.0 / 2012-09-19
* fixed logic bug that caused bar to jump one extra space at the end [davglass]
* working with readline impl, even on Windows [davglass]
* using readline instead of the \r hack [davglass]
### 0.0.5 / 2012-08-07
* add ability to tick by zero chunks - tick(0)
* fix ETA. Closes #4 [lwille]
0.0.4 / 2011-11-14
==================
### 0.0.4 / 2011-11-14
* Allow more recent versions of node
* allow more recent versions of node
0.0.3 / 2011-04-20
==================
### 0.0.3 / 2011-04-20
* Changed; erase the line when complete
* changed; erase the line when complete
0.0.2 / 2011-04-20
==================
### 0.0.2 / 2011-04-20
* Added custom tokens support
* Fixed; clear line before writing
* added custom tokens support
* fixed; clear line before writing
0.0.1 / 2010-01-03
==================
### 0.0.1 / 2010-01-03
* Initial release
* initial release

@@ -14,4 +14,4 @@ /*!

/**
* Initialize a `ProgressBar` with the given
* `fmt` string and `options` or `total`.
* Initialize a `ProgressBar` with the given `fmt` string and `options` or
* `total`.
*

@@ -26,2 +26,3 @@ * Options:

* - `callback` optional function to call when the progress bar completes
* - `clear` will clear the progress bar upon termination
*

@@ -37,4 +38,4 @@ * Tokens:

*
* @param {String} fmt
* @param {Object|Number} options or total
* @param {string} fmt
* @param {object|number} options or total
* @api public

@@ -45,10 +46,2 @@ */

this.stream = options.stream || process.stderr;
this.rl = require('readline').createInterface({
input: process.stdin,
output: this.stream
});
this.rl.setPrompt('', 0);
this.rl.clearLine = function() {
this.write(null, {ctrl: true, name: 'u'});
};

@@ -71,4 +64,4 @@ if (typeof(options) == 'number') {

this.chars = {
complete: options.complete || '='
, incomplete: options.incomplete || '-'
complete : options.complete || '=',
incomplete : options.incomplete || '-'
};

@@ -80,7 +73,6 @@ this.callback = options.callback || function () {};

/**
* "tick" the progress bar with optional `len` and
* optional `tokens`.
* "tick" the progress bar with optional `len` and optional `tokens`.
*
* @param {Number|Object} len or tokens
* @param {Object} tokens
* @param {number|object} len or tokens
* @param {object} tokens
* @api public

@@ -112,13 +104,11 @@ */

/**
* Method to render the progress bar with optional `tokens` to
* place in the progress bar's `fmt` field.
* Method to render the progress bar with optional `tokens` to place in the
* progress bar's `fmt` field.
*
* @param {Object} tokens
* @param {object} tokens
* @api public
*/
ProgressBar.prototype.render = function(tokens){
if (!this.stream.isTTY) {
return;
}
ProgressBar.prototype.render = function (tokens) {
if (!this.stream.isTTY) return;

@@ -128,7 +118,7 @@ var ratio = this.curr / this.total;

var percent = ratio * 100
, complete = Math.round(this.width * ratio)
, incomplete
, elapsed = new Date - this.start
, eta = (percent == 100) ? 0 : elapsed * (this.total / this.curr - 1);
var percent = ratio * 100;
var complete = Math.round(this.width * ratio);
var incomplete;
var elapsed = new Date - this.start;
var eta = (percent == 100) ? 0 : elapsed * (this.total / this.curr - 1);

@@ -142,15 +132,13 @@ complete = Array(complete).join(this.chars.complete);

.replace(':total', this.total)
.replace(':elapsed', isNaN(elapsed) ? "0.0" : (elapsed / 1000).toFixed(1))
.replace(':eta', (isNaN(eta) || !isFinite(eta)) ? "0.0" : (eta / 1000).toFixed(1))
.replace(':elapsed', isNaN(elapsed) ? '0.0' : (elapsed / 1000).toFixed(1))
.replace(':eta', (isNaN(eta) || !isFinite(eta)) ? '0.0' : (eta / 1000)
.toFixed(1))
.replace(':percent', percent.toFixed(0) + '%');
if (tokens) {
for (var key in tokens) {
str = str.replace(':' + key, tokens[key]);
}
}
if (tokens) for (var key in tokens) str = str.replace(':' + key, tokens[key]);
if (this.lastDraw !== str) {
this.rl.clearLine();
this.rl.write(str);
this.stream.clearLine();
this.stream.cursorTo(0);
this.stream.write(str);
this.lastDraw = str;

@@ -169,8 +157,8 @@ }

*
* @param {Number} ratio The ratio (between 0 and 1 inclusive) to set the
* overall completion to.
* @param {number} ratio The ratio (between 0 and 1 inclusive) to set the
* overall completion to.
* @api public
*/
ProgressBar.prototype.update = function(ratio, tokens) {
ProgressBar.prototype.update = function (ratio, tokens) {
var goal = Math.floor(ratio * this.total);

@@ -188,12 +176,7 @@ var delta = goal - this.curr;

ProgressBar.prototype.terminate = function() {
this.rl.resume();
ProgressBar.prototype.terminate = function () {
if (this.clear) {
this.rl.clearLine();
this.rl.close();
} else {
this.rl.close();
console.log();
}
this.stream.clearLine();
this.stream.cursorTo(0);
} else console.log();
};
{
"name": "progress"
, "version": "1.1.4"
, "version": "1.1.5"
, "description": "Flexible ascii progress bar"

@@ -5,0 +5,0 @@ , "keywords": ["cli", "progress"]

@@ -1,14 +0,14 @@

# node-progress
Flexible ascii progress bar.
Flexible ascii progress bar
## Installation
npm install progress
```bash
$ npm install progress
```
## Usage
First we create a `ProgressBar`, giving it a format string
as well as the `total`, telling the progress bar when it will
be considered complete. After that all we need to do is `tick()` appropriately.
First we create a `ProgressBar`, giving it a format string
as well as the `total`, telling the progress bar when it will
be considered complete. After that all we need to do is `tick()` appropriately.

@@ -19,3 +19,3 @@ ```javascript

var bar = new ProgressBar(':bar', { total: 10 });
var timer = setInterval(function(){
var timer = setInterval(function () {
bar.tick();

@@ -29,21 +29,26 @@ if (bar.complete) {

## Options:
### Options
- `total` total number of ticks to complete
- `width` the displayed width of the progress bar defaulting to total
- `stream` the output stream defaulting to stderr
- `complete` completion character defaulting to "="
- `incomplete` incomplete character defaulting to "-"
- `clear` option to clear the bar on completion defaulting to false
- `callback` optional function to call when the progress bar completes
These are keys in the options object you can pass to the progress bar along with
`total` as seen in the example above.
## Tokens:
- `total` total number of ticks to complete
- `width` the displayed width of the progress bar defaulting to total
- `stream` the output stream defaulting to stderr
- `complete` completion character defaulting to "="
- `incomplete` incomplete character defaulting to "-"
- `clear` option to clear the bar on completion defaulting to false
- `callback` optional function to call when the progress bar completes
- `:bar` the progress bar itself
- `:current` current tick number
- `:total` total ticks
- `:elapsed` time elapsed in seconds
- `:percent` completion percentage
- `:eta` estimated completion time in seconds
### Tokens
These are tokens you can use in the format of your progress bar.
- `:bar` the progress bar itself
- `:current` current tick number
- `:total` total ticks
- `:elapsed` time elapsed in seconds
- `:percent` completion percentage
- `:eta` estimated completion time in seconds
## Examples

@@ -53,12 +58,14 @@

In our download example each tick has a variable influence, so we pass the chunk length which adjusts the progress bar appropriately relative to the total length.
In our download example each tick has a variable influence, so we pass the chunk
length which adjusts the progress bar appropriately relative to the total
length.
```javascript
var ProgressBar = require('../')
, https = require('https');
var ProgressBar = require('../');
var https = require('https');
var req = https.request({
host: 'download.github.com'
, port: 443
, path: '/visionmedia-node-jscoverage-0d4608a.zip'
host: 'download.github.com',
port: 443,
path: '/visionmedia-node-jscoverage-0d4608a.zip'
});

@@ -71,13 +78,13 @@

var bar = new ProgressBar(' downloading [:bar] :percent :etas', {
complete: '='
, incomplete: ' '
, width: 20
, total: len
complete: '=',
incomplete: ' ',
width: 20,
total: len
});
res.on('data', function(chunk){
res.on('data', function (chunk) {
bar.tick(chunk.length);
});
res.on('end', function(){
res.on('end', function () {
console.log('\n');

@@ -90,3 +97,3 @@ });

The code above will generate a progress bar that looks like this:
The above example result in a progress bar like the one below.

@@ -101,23 +108,2 @@ ```

(The MIT License)
Copyright (c) 2011 TJ Holowaychuk `<tj@vision-media.ca>`
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc