mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-25 11:11:46 +08:00
Merge pull request #5720 from sebastian-lenz/master
Add node-progress definition
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/// <reference path="progress.d.ts"/>
|
||||
|
||||
var ProgressBar = require('progress');
|
||||
|
||||
|
||||
/**
|
||||
* Usage example from https://github.com/tj/node-progress
|
||||
*/
|
||||
var bar = new ProgressBar(':bar', { total: 10 });
|
||||
var timer = setInterval(function () {
|
||||
bar.tick();
|
||||
if (bar.complete) {
|
||||
console.log('\ncomplete\n');
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 100);
|
||||
|
||||
|
||||
/**
|
||||
* Custom token example from https://github.com/tj/node-progress
|
||||
*/
|
||||
var bar = new ProgressBar(':current: :token1 :token2', { total: 3 });
|
||||
|
||||
bar.tick({
|
||||
'token1': "Hello",
|
||||
'token2': "World!\n"
|
||||
});
|
||||
|
||||
bar.tick(2, {
|
||||
'token1': "Goodbye",
|
||||
'token2': "World!"
|
||||
});
|
||||
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
// Type definitions for node-progress v1.1.8
|
||||
// Project: https://github.com/tj/node-progress
|
||||
// Definitions by: Sebastian Lenz <https://github.com/sebastian-lenz>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts"/>
|
||||
|
||||
|
||||
declare module "progress"
|
||||
{
|
||||
/**
|
||||
* These are keys in the options object you can pass to the progress bar along with total as seen in the example above.
|
||||
*/
|
||||
interface ProgressBarOptions
|
||||
{
|
||||
/**
|
||||
* Total number of ticks to complete.
|
||||
*/
|
||||
total:number;
|
||||
|
||||
/**
|
||||
* The displayed width of the progress bar defaulting to total.
|
||||
*/
|
||||
width?:number;
|
||||
|
||||
/**
|
||||
* The output stream defaulting to stderr.
|
||||
*/
|
||||
stream?:NodeJS.WritableStream;
|
||||
|
||||
/**
|
||||
* Completion character defaulting to "=".
|
||||
*/
|
||||
complete?:string;
|
||||
|
||||
/**
|
||||
* Incomplete character defaulting to "-".
|
||||
*/
|
||||
incomplete?:string;
|
||||
|
||||
/**
|
||||
* Option to clear the bar on completion defaulting to false.
|
||||
*/
|
||||
clear?:boolean;
|
||||
|
||||
/**
|
||||
* Optional function to call when the progress bar completes.
|
||||
*/
|
||||
callback?:Function;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flexible ascii progress bar.
|
||||
*/
|
||||
class ProgressBar
|
||||
{
|
||||
/**
|
||||
* Initialize a `ProgressBar` with the given `fmt` string and `options` or
|
||||
* `total`.
|
||||
*
|
||||
* 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 "-"
|
||||
* - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
|
||||
* - `callback` optional function to call when the progress bar completes
|
||||
* - `clear` will clear the progress bar upon termination
|
||||
*
|
||||
* Tokens:
|
||||
* - `:bar` the progress bar itself
|
||||
* - `:current` current tick number
|
||||
* - `:total` total ticks
|
||||
* - `:elapsed` time elapsed in seconds
|
||||
* - `:percent` completion percentage
|
||||
* - `:eta` eta in seconds
|
||||
*/
|
||||
constructor(format:string, total:number);
|
||||
constructor(format:string, options:ProgressBarOptions);
|
||||
|
||||
|
||||
/**
|
||||
* "tick" the progress bar with optional `len` and optional `tokens`.
|
||||
*/
|
||||
tick(tokens?:any):void;
|
||||
tick(count?:number, tokens?:any):void;
|
||||
|
||||
|
||||
/**
|
||||
* Method to render the progress bar with optional `tokens` to place in the
|
||||
* progress bar's `fmt` field.
|
||||
*/
|
||||
render(tokens?:any):void;
|
||||
|
||||
|
||||
/**
|
||||
* "update" the progress bar to represent an exact percentage.
|
||||
* The ratio (between 0 and 1) specified will be multiplied by `total` and
|
||||
* floored, representing the closest available "tick." For example, if a
|
||||
* progress bar has a length of 3 and `update(0.5)` is called, the progress
|
||||
* will be set to 1.
|
||||
*
|
||||
* A ratio of 0.5 will attempt to set the progress to halfway.
|
||||
*
|
||||
* @param ratio The ratio (between 0 and 1 inclusive) to set the
|
||||
* overall completion to.
|
||||
*/
|
||||
update(ratio:number, tokens?:any):void;
|
||||
|
||||
|
||||
/**
|
||||
* Terminates a progress bar.
|
||||
*/
|
||||
terminate():void;
|
||||
}
|
||||
|
||||
|
||||
export = ProgressBar;
|
||||
}
|
||||
Reference in New Issue
Block a user