From 1e55782c9d47d996ab5c88988062020ce894e57b Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Mon, 7 Sep 2015 15:53:42 +0200 Subject: [PATCH 1/4] Add node-progress definition --- node-progress/node-progress.d.ts | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 node-progress/node-progress.d.ts diff --git a/node-progress/node-progress.d.ts b/node-progress/node-progress.d.ts new file mode 100644 index 000000000..2c7e683ec --- /dev/null +++ b/node-progress/node-progress.d.ts @@ -0,0 +1,121 @@ +// Type definitions for node-progress v1.1.8 +// Project: https://github.com/tj/node-progress +// Definitions by: Sebastian Lenz +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + + +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; +} From 2cdbc68f690138410785db1cb4fcbd64e36e4203 Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Mon, 7 Sep 2015 15:54:34 +0200 Subject: [PATCH 2/4] Add test case for node-progress --- node-progress/node-progress-test.ts | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 node-progress/node-progress-test.ts diff --git a/node-progress/node-progress-test.ts b/node-progress/node-progress-test.ts new file mode 100644 index 000000000..1e723aabe --- /dev/null +++ b/node-progress/node-progress-test.ts @@ -0,0 +1,32 @@ +/// + +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!" +}); From 2c55e6f76c8799c5a0b3a5c7e4cfc6da00aeaa4f Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Tue, 8 Sep 2015 12:18:05 +0200 Subject: [PATCH 3/4] Rename "node-progress" to "progress" --- node-progress/node-progress-test.ts => progress/progress-test.ts | 0 node-progress/node-progress.d.ts => progress/progress.d.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename node-progress/node-progress-test.ts => progress/progress-test.ts (100%) rename node-progress/node-progress.d.ts => progress/progress.d.ts (100%) diff --git a/node-progress/node-progress-test.ts b/progress/progress-test.ts similarity index 100% rename from node-progress/node-progress-test.ts rename to progress/progress-test.ts diff --git a/node-progress/node-progress.d.ts b/progress/progress.d.ts similarity index 100% rename from node-progress/node-progress.d.ts rename to progress/progress.d.ts From 5558a68cce3f867236f680e504737daaa5f0a80a Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Tue, 8 Sep 2015 12:20:06 +0200 Subject: [PATCH 4/4] Update test case --- progress/progress-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progress/progress-test.ts b/progress/progress-test.ts index 1e723aabe..699c20b05 100644 --- a/progress/progress-test.ts +++ b/progress/progress-test.ts @@ -1,4 +1,4 @@ -/// +/// var ProgressBar = require('progress');