From 3666c21e7a03513564da1645a2524023bbfc814f Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 14:13:58 -0800 Subject: [PATCH 1/8] update test to be in actual typescript --- types/progress/progress-tests.ts | 60 ++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/types/progress/progress-tests.ts b/types/progress/progress-tests.ts index 561f226b64..d93eb9bc3f 100644 --- a/types/progress/progress-tests.ts +++ b/types/progress/progress-tests.ts @@ -1,42 +1,48 @@ -var ProgressBar = require('progress'); +import * as ProgressBar from 'progress'; /** - * Usage example from https://github.com/tj/node-progress + * Usage example from https://github.com/visionmedia/node-progress + * (in Typescript) */ -var bar = new ProgressBar(':bar', { total: 10 }); -var timer = setInterval(function () { - bar.tick(); - if (bar.complete) { +const usageBar = new ProgressBar(':bar', { total: 10 }); +const timer = setInterval(function () { + usageBar.tick(); + if (usageBar.complete) { console.log('\ncomplete\n'); clearInterval(timer); } }, 100); - /** - * Custom token example from https://github.com/tj/node-progress + * Custom token example from https://github.com/visionmedia/node-progress + * (in Typescript) */ -var bar = new ProgressBar(':current: :token1 :token2', { total: 3 }); - -bar.tick({ - 'token1': "Hello", - 'token2': "World!\n" -}); - -bar.tick(2, { - 'token1': "Goodbye", - 'token2': "World!" -}); + const list = [ + 'image01.jpg', 'image02.jpg', 'image03.jpg', 'image04.jpg', 'image05.jpg', + 'image06.jpg', 'image07.jpg', 'image08.jpg', 'image09.jpg', 'image10.jpg' + ]; + const customTokenBar = new ProgressBar(':percent eta: :eta downloading :current/:total :file', { + total: list.length + }); + const customInterval = setInterval(function (){ + customTokenBar.tick({ + 'file': list[customTokenBar.curr] + }) + if (customTokenBar.complete) { + clearInterval(customInterval) + } + }, 500) /** * Interrupt example from https://github.com/visionmedia/node-progress + * (in Typescript) */ -var bar = new ProgressBar(':bar :current/:total', { total: 10 }); -var timer = setInterval(function () { - bar.tick(); - if (bar.complete) { - clearInterval(timer); - } else if (bar.curr === 5) { - bar.interrupt('this message appears above the progress bar\ncurrent progress is ' + bar.curr + '/' + bar.total); +const interruptBar = new ProgressBar(':bar :current/:total', { total: 10 }); +const interruptTimer = setInterval(function () { + interruptBar.tick(); + if (interruptBar.complete) { + clearInterval(interruptTimer); + } else if (interruptBar.curr === 5 || interruptBar.curr === 8) { + interruptBar.interrupt('interrupt: current progress is ' + interruptBar.curr + '/' + interruptBar.total); } -}, 1000); \ No newline at end of file +}, 1000); From a384bde65de2809a7ba25c460518148ec156ee8c Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 14:34:19 -0800 Subject: [PATCH 2/8] export as a namespace so the class and options are visible --- types/progress/index.d.ts | 132 ++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 61 deletions(-) diff --git a/types/progress/index.d.ts b/types/progress/index.d.ts index 6f6e2ea33d..6422dabbdc 100644 --- a/types/progress/index.d.ts +++ b/types/progress/index.d.ts @@ -1,67 +1,13 @@ // Type definitions for node-progress v2.0.0 -// Project: https://github.com/tj/node-progress +// Project: https://github.com/visionmedia/node-progress // Definitions by: Sebastian Lenz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// +export as namespace ProgressBar; - -/** - * These are keys in the options object you can pass to the progress bar along with total as seen in the example above. - */ -export interface ProgressBarOptions { - /** - * Total number of ticks to complete. - */ - total: number; - - /** - * current completed index - */ - curr?: number; - - /** - * head character defaulting to complete character - */ - head?: string; - - /** - * The displayed width of the progress bar defaulting to total. - */ - width?: number; - - /** - * minimum time between updates in milliseconds defaulting to 16 - */ - renderThrottle?: 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; -} - +export = ProgressBar; /** * Flexible ascii progress bar. @@ -90,7 +36,7 @@ declare class ProgressBar { * - `:eta` eta in seconds */ constructor(format: string, total: number); - constructor(format: string, options: ProgressBarOptions); + constructor(format: string, options: ProgressBar.ProgressBarOptions); /** @@ -135,7 +81,71 @@ declare class ProgressBar { * Completed status of progress (Boolean) */ complete: boolean; -} -declare namespace ProgressBar { } -export default ProgressBar; + /** + * Current tick number. + */ + curr: number; + + /** + * Total number of ticks to complete. + */ + total: number; +} + +declare namespace ProgressBar { + /** + * 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; + + /** + * current completed index + */ + curr?: number; + + /** + * head character defaulting to complete character + */ + head?: string; + + /** + * The displayed width of the progress bar defaulting to total. + */ + width?: number; + + /** + * minimum time between updates in milliseconds defaulting to 16 + */ + renderThrottle?: 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; + } +} From db1fac022e5b3a28487e4100342a7da783024a35 Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 14:34:55 -0800 Subject: [PATCH 3/8] fix inclusion of progress module --- types/multi-progress/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/multi-progress/index.d.ts b/types/multi-progress/index.d.ts index db15a15b1b..a98057ecc8 100644 --- a/types/multi-progress/index.d.ts +++ b/types/multi-progress/index.d.ts @@ -5,7 +5,7 @@ /// -import ProgressBar, { ProgressBarOptions } from 'progress'; +import * as ProgressBar from 'progress'; import { Stream } from 'stream'; export default class MultiProgress { @@ -18,7 +18,7 @@ export default class MultiProgress { /** * Add a new bar */ - newBar: (format: string, options: ProgressBarOptions) => ProgressBar; + newBar: (format: string, options: ProgressBar.ProgressBarOptions) => ProgressBar; /** * Close all bars From 4f40fdc2ec032e766d72bf3fa5fbdc8fa53eec17 Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 14:47:24 -0800 Subject: [PATCH 4/8] fix multi-progress typing to expose constructor as namespace --- types/multi-progress/index.d.ts | 8 +++++++- types/multi-progress/multi-progress-tests.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/types/multi-progress/index.d.ts b/types/multi-progress/index.d.ts index a98057ecc8..31dd11b710 100644 --- a/types/multi-progress/index.d.ts +++ b/types/multi-progress/index.d.ts @@ -8,7 +8,11 @@ import * as ProgressBar from 'progress'; import { Stream } from 'stream'; -export default class MultiProgress { +export as namespace MultiProgress; + +export = MultiProgress; + +declare class MultiProgress { /** * Create a new @see MultiProgress with the given stream, or stderr by default * @param stream A stream to write the progress bars to @@ -40,3 +44,5 @@ export default class MultiProgress { */ update: (index: number, value: number, options?: any) => void; } + +declare namespace MultiProgress {} diff --git a/types/multi-progress/multi-progress-tests.ts b/types/multi-progress/multi-progress-tests.ts index 9dde27c16b..b14806b7c5 100644 --- a/types/multi-progress/multi-progress-tests.ts +++ b/types/multi-progress/multi-progress-tests.ts @@ -3,7 +3,7 @@ */ // require the library -import MultiProgress from 'multi-progress'; +import * as MultiProgress from 'multi-progress'; // spawn an instance with the optional stream to write to // use of `new` is optional From bc53931e5057c294dfdd1f53e86f61aa5ffa1004 Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 14:54:02 -0800 Subject: [PATCH 5/8] fix version number --- types/multi-progress/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/multi-progress/index.d.ts b/types/multi-progress/index.d.ts index 31dd11b710..d06f941fbb 100644 --- a/types/multi-progress/index.d.ts +++ b/types/multi-progress/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for multi-progress 2.0 +// Type definitions for multi-progress 2.0.0 // Project: https://github.com/pitaj/multi-progress // Definitions by: David Brett // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From 2a93d32f56ea529bf62cf2b979cb0a8e5ae987bb Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 14:54:12 -0800 Subject: [PATCH 6/8] fix version number --- types/progress/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/progress/index.d.ts b/types/progress/index.d.ts index 6422dabbdc..ba9b0eb261 100644 --- a/types/progress/index.d.ts +++ b/types/progress/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for node-progress v2.0.0 +// Type definitions for node-progress v2.0.3 // Project: https://github.com/visionmedia/node-progress // Definitions by: Sebastian Lenz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From e265533307c820a080e2a5e5d0e2a50dec957d01 Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 15:01:12 -0800 Subject: [PATCH 7/8] multi-progress version to '2.0' --- types/multi-progress/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/multi-progress/index.d.ts b/types/multi-progress/index.d.ts index d06f941fbb..31dd11b710 100644 --- a/types/multi-progress/index.d.ts +++ b/types/multi-progress/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for multi-progress 2.0.0 +// Type definitions for multi-progress 2.0 // Project: https://github.com/pitaj/multi-progress // Definitions by: David Brett // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From e553952abcc391cf83cb2d679b6a91cbc1b3a147 Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Thu, 13 Dec 2018 15:02:05 -0800 Subject: [PATCH 8/8] progress type to '2.0' --- types/progress/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/progress/index.d.ts b/types/progress/index.d.ts index ba9b0eb261..c1e199ec6c 100644 --- a/types/progress/index.d.ts +++ b/types/progress/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for node-progress v2.0.3 +// Type definitions for node-progress 2.0 // Project: https://github.com/visionmedia/node-progress // Definitions by: Sebastian Lenz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped