Skip to content

Commit 8af72d1

Browse files
committed
Merge pull request DefinitelyTyped#5720 from sebastian-lenz/master
Add node-progress definition
2 parents 4cd6114 + 5558a68 commit 8af72d1

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

progress/progress-test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference path="progress.d.ts"/>
2+
3+
var ProgressBar = require('progress');
4+
5+
6+
/**
7+
* Usage example from https://github.com/tj/node-progress
8+
*/
9+
var bar = new ProgressBar(':bar', { total: 10 });
10+
var timer = setInterval(function () {
11+
bar.tick();
12+
if (bar.complete) {
13+
console.log('\ncomplete\n');
14+
clearInterval(timer);
15+
}
16+
}, 100);
17+
18+
19+
/**
20+
* Custom token example from https://github.com/tj/node-progress
21+
*/
22+
var bar = new ProgressBar(':current: :token1 :token2', { total: 3 });
23+
24+
bar.tick({
25+
'token1': "Hello",
26+
'token2': "World!\n"
27+
});
28+
29+
bar.tick(2, {
30+
'token1': "Goodbye",
31+
'token2': "World!"
32+
});

progress/progress.d.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Type definitions for node-progress v1.1.8
2+
// Project: https://github.com/tj/node-progress
3+
// Definitions by: Sebastian Lenz <https://github.com/sebastian-lenz>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../node/node.d.ts"/>
7+
8+
9+
declare module "progress"
10+
{
11+
/**
12+
* These are keys in the options object you can pass to the progress bar along with total as seen in the example above.
13+
*/
14+
interface ProgressBarOptions
15+
{
16+
/**
17+
* Total number of ticks to complete.
18+
*/
19+
total:number;
20+
21+
/**
22+
* The displayed width of the progress bar defaulting to total.
23+
*/
24+
width?:number;
25+
26+
/**
27+
* The output stream defaulting to stderr.
28+
*/
29+
stream?:NodeJS.WritableStream;
30+
31+
/**
32+
* Completion character defaulting to "=".
33+
*/
34+
complete?:string;
35+
36+
/**
37+
* Incomplete character defaulting to "-".
38+
*/
39+
incomplete?:string;
40+
41+
/**
42+
* Option to clear the bar on completion defaulting to false.
43+
*/
44+
clear?:boolean;
45+
46+
/**
47+
* Optional function to call when the progress bar completes.
48+
*/
49+
callback?:Function;
50+
}
51+
52+
53+
/**
54+
* Flexible ascii progress bar.
55+
*/
56+
class ProgressBar
57+
{
58+
/**
59+
* Initialize a `ProgressBar` with the given `fmt` string and `options` or
60+
* `total`.
61+
*
62+
* Options:
63+
* - `total` total number of ticks to complete
64+
* - `width` the displayed width of the progress bar defaulting to total
65+
* - `stream` the output stream defaulting to stderr
66+
* - `complete` completion character defaulting to "="
67+
* - `incomplete` incomplete character defaulting to "-"
68+
* - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
69+
* - `callback` optional function to call when the progress bar completes
70+
* - `clear` will clear the progress bar upon termination
71+
*
72+
* Tokens:
73+
* - `:bar` the progress bar itself
74+
* - `:current` current tick number
75+
* - `:total` total ticks
76+
* - `:elapsed` time elapsed in seconds
77+
* - `:percent` completion percentage
78+
* - `:eta` eta in seconds
79+
*/
80+
constructor(format:string, total:number);
81+
constructor(format:string, options:ProgressBarOptions);
82+
83+
84+
/**
85+
* "tick" the progress bar with optional `len` and optional `tokens`.
86+
*/
87+
tick(tokens?:any):void;
88+
tick(count?:number, tokens?:any):void;
89+
90+
91+
/**
92+
* Method to render the progress bar with optional `tokens` to place in the
93+
* progress bar's `fmt` field.
94+
*/
95+
render(tokens?:any):void;
96+
97+
98+
/**
99+
* "update" the progress bar to represent an exact percentage.
100+
* The ratio (between 0 and 1) specified will be multiplied by `total` and
101+
* floored, representing the closest available "tick." For example, if a
102+
* progress bar has a length of 3 and `update(0.5)` is called, the progress
103+
* will be set to 1.
104+
*
105+
* A ratio of 0.5 will attempt to set the progress to halfway.
106+
*
107+
* @param ratio The ratio (between 0 and 1 inclusive) to set the
108+
* overall completion to.
109+
*/
110+
update(ratio:number, tokens?:any):void;
111+
112+
113+
/**
114+
* Terminates a progress bar.
115+
*/
116+
terminate():void;
117+
}
118+
119+
120+
export = ProgressBar;
121+
}

0 commit comments

Comments
 (0)