diff --git a/types/index.d.ts b/types/index.d.ts index 52c2413..efbb88f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,37 +1,47 @@ import { Chalk } from 'chalk'; -export interface Spinner { - interval: number; - frames: string[]; -} +declare namespace progressEstimator { + interface Spinner { + interval: number; + frames: string[]; + } -export interface ChalkTheme extends Chalk { - asciiCompleted: Chalk; - asciiInProgress: Chalk; - estimate: Chalk; - estimateExceeded: Chalk; - label: Chalk; - percentage: Chalk; - progressBackground: Chalk; - progressForeground: Chalk; -} + interface ChalkTheme extends Chalk { + asciiCompleted: Chalk; + asciiInProgress: Chalk; + estimate: Chalk; + estimateExceeded: Chalk; + label: Chalk; + percentage: Chalk; + progressBackground: Chalk; + progressForeground: Chalk; + } -export interface Configuration { - spinner?: Spinner; - storagePath?: string; - theme?: ChalkTheme; -} + interface LogFunction { + (...text: string[]): void; + clear(): void; + done(): void; + } + + interface Configuration { + logFunction?: LogFunction; + spinner?: Spinner; + storagePath?: string; + theme?: ChalkTheme; + } + + interface LogOption { + estimate?: number; + id?: string; + } -export interface ProgressEstimator { - (promise: Promise, label: string, estimatedDuration?: number): Promise< - T - >; - configure(options: Configuration): void; - logProgress: ProgressEstimator; + interface ProgressEstimator { + (promise: Promise, label: string, options?: LogOption): Promise; + } } -export declare const configure: (options: Configuration) => void; -export declare const logProgress: ProgressEstimator; +declare function progressEstimator( + config?: progressEstimator.Configuration +): progressEstimator.ProgressEstimator; -declare const progressEstimator: ProgressEstimator; -export default progressEstimator; +export = progressEstimator; diff --git a/types/test.ts b/types/test.ts index b452f63..07e6c41 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,5 +1,5 @@ import chalk from 'chalk'; -import progressEstimator, { configure, logProgress, ChalkTheme } from '..'; +import createLogger, { ChalkTheme, LogFunction } from '..'; // Test promises const stringPromise = new Promise(resolve => resolve('hello')); @@ -16,35 +16,42 @@ chalkTheme.percentage = chalkTheme; chalkTheme.progressBackground = chalkTheme; chalkTheme.progressForeground = chalkTheme; -// Check `logProgress` -const resultOne: Promise = progressEstimator( - stringPromise, - 'This promise has no initial estimate' -); -const resultTwo: Promise = progressEstimator( - numberPromise, - 'This promise is initially estimated to take 1 second', - 1000 -); -const resultThree: Promise = logProgress(numberPromise, 'Valid export'); +// logFunction +const logFunction: LogFunction = (...text: string[]) => {}; +logFunction.done = () => {}; +logFunction.clear = () => {}; -// Check `configure` -configure({ - spinner: { interval: 100, frames: ['.', ''] } +// Check `createLogger` +const logger = createLogger(); +createLogger({ + spinner: { + interval: 100, + frames: ['.', ''] + } }); -configure({ +createLogger({ storagePath: 'path/to/dir' }); -configure({ +createLogger({ theme: chalkTheme }); -configure({ - spinner: { interval: 100, frames: ['.', ''] }, - storagePath: 'path/to/dir', - theme: chalkTheme +createLogger({ + logFunction: logFunction }); -progressEstimator.configure({ +createLogger({ spinner: { interval: 100, frames: ['.', ''] }, storagePath: 'path/to/dir', - theme: chalkTheme + theme: chalkTheme, + logFunction: logFunction }); + +const resultOne: Promise = logger( + stringPromise, + 'This promise has no initial estimate' +); +const resultTwo: Promise = logger( + numberPromise, + 'This promise is initially estimated to take 1 second', + { estimate: 1000 } +); +const resultThree: Promise = logger(numberPromise, 'Valid export'); diff --git a/types/tsconfig.json b/types/tsconfig.json index 40b17ad..57b19fd 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json @@ -2,10 +2,9 @@ "compilerOptions": { "module": "commonjs", "target": "es6", - "lib": ["es2015"], "noImplicitAny": true, "noUnusedLocals": false, "noEmit": true, - "allowJs": true + "esModuleInterop": true } }