Added test for Typescript definition

This commit is contained in:
Thomas Sauer 2017-07-02 14:32:45 +02:00
parent 3cd849197d
commit f18decbd7f
4 changed files with 43 additions and 2 deletions

80
types/index.d.ts vendored Normal file
View file

@ -0,0 +1,80 @@
// Type definitions for Chalk 2
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
export = chalk;
declare function chalk(...text: (string | number)[]): string;
declare function chalk(text: TemplateStringsArray, ...placeholders: (string | number)[]): string;
declare namespace chalk {
interface ChalkConstructorOptions {
enabled?: boolean;
level?: number;
}
export function constructor(options?: ChalkConstructorOptions): typeof chalk;
export let enabled: boolean;
export let level: number;
export const supportsColor: boolean;
export const hex: (color: string) => typeof chalk;
export const keyword: (color: string) => typeof chalk;
export const rgb: (r: number, g: number, b: number) => typeof chalk;
export const hsl: (h: number, s: number, l: number) => typeof chalk;
export const hsv: (h: number, s: number, v: number) => typeof chalk;
export const hwb: (h: number, w: number, b: number) => typeof chalk;
export const bgHex: (color: string) => typeof chalk;
export const bgKeyword: (color: string) => typeof chalk;
export const bgRgb: (r: number, g: number, b: number) => typeof chalk;
export const bgHsl: (h: number, s: number, l: number) => typeof chalk;
export const bgHsv: (h: number, s: number, v: number) => typeof chalk;
export const bgHwb: (h: number, w: number, b: number) => typeof chalk;
export const reset: typeof chalk;
export const bold: typeof chalk;
export const dim: typeof chalk;
export const italic: typeof chalk;
export const underline: typeof chalk;
export const inverse: typeof chalk;
export const hidden: typeof chalk;
export const strikethrough: typeof chalk;
export const black: typeof chalk;
export const red: typeof chalk;
export const green: typeof chalk;
export const yellow: typeof chalk;
export const blue: typeof chalk;
export const magenta: typeof chalk;
export const cyan: typeof chalk;
export const white: typeof chalk;
export const gray: typeof chalk;
export const grey: typeof chalk;
export const blackBright: typeof chalk;
export const redBright: typeof chalk;
export const greenBright: typeof chalk;
export const yellowBright: typeof chalk;
export const blueBright: typeof chalk;
export const magentaBright: typeof chalk;
export const cyanBright: typeof chalk;
export const whiteBright: typeof chalk;
export const bgBlack: typeof chalk;
export const bgRed: typeof chalk;
export const bgGreen: typeof chalk;
export const bgYellow: typeof chalk;
export const bgBlue: typeof chalk;
export const bgMagenta: typeof chalk;
export const bgCyan: typeof chalk;
export const bgWhite: typeof chalk;
export const bgBlackBright: typeof chalk;
export const bgRedBright: typeof chalk;
export const bgGreenBright: typeof chalk;
export const bgYellowBright: typeof chalk;
export const bgBlueBright: typeof chalk;
export const bgMagentaBright: typeof chalk;
export const bgCyanBright: typeof chalk;
export const bgWhiteBright: typeof chalk;
}

31
types/test.ts Normal file
View file

@ -0,0 +1,31 @@
import * as chalk from '../.';
chalk.underline('foo');
chalk.red('foo');
chalk.bgRed('foo');
chalk.red`foo`;
chalk.underline`foo`;
chalk`foo`;
chalk.red.bgGreen.underline('foo');
chalk.underline.red.bgGreen('foo');
chalk.grey('foo');
chalk.red(0);
const ctx = chalk.constructor({level: 1});
ctx('foo');
ctx.red('foo');
ctx`foo`;
chalk.enabled;
chalk.supportsColor;
chalk.level;
chalk.keyword('orange').bgBlue('foo');
chalk.hex('#123456').bgBlue('foo');
chalk.rgb(1, 14, 9).bgBlue('foo');
chalk.hsl(1, 14, 9).bgBlue('foo');
chalk.hsv(1, 14, 9).bgBlue('foo');
chalk.hwb(1, 14, 9).bgBlue('foo');

9
types/tsconfig.json Normal file
View file

@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noEmit": true,
"allowJs": true
}
}