This commit is contained in:
Thomas Sauer 2017-07-23 20:13:59 +00:00 committed by GitHub
commit e3e021d788
4 changed files with 141 additions and 2 deletions

View file

@ -8,13 +8,14 @@
"node": ">=4" "node": ">=4"
}, },
"scripts": { "scripts": {
"test": "xo && nyc mocha", "test": "xo && tsc --project types && nyc mocha",
"bench": "matcha benchmark.js", "bench": "matcha benchmark.js",
"coveralls": "nyc report --reporter=text-lcov | coveralls" "coveralls": "nyc report --reporter=text-lcov | coveralls"
}, },
"files": [ "files": [
"index.js", "index.js",
"templates.js" "templates.js",
"types/index.d.ts"
], ],
"keywords": [ "keywords": [
"color", "color",
@ -52,8 +53,10 @@
"mocha": "*", "mocha": "*",
"nyc": "^11.0.2", "nyc": "^11.0.2",
"resolve-from": "^3.0.0", "resolve-from": "^3.0.0",
"typescript": "^2.4.1",
"xo": "*" "xo": "*"
}, },
"types": "types/index.d.ts",
"xo": { "xo": {
"envs": [ "envs": [
"node", "node",

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

@ -0,0 +1,87 @@
// Type definitions for Chalk
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
export default chalk;
declare function chalk(...text: string[]): string;
declare function chalk(text: TemplateStringsArray, ...placeholders: string[]): string;
declare namespace chalk {
export enum Level {
None = 0,
Basic = 1,
Extended = 2,
TrueColor = 3
}
interface ConstructorOptions {
enabled?: boolean;
level?: Level;
}
export function constructor(options?: ConstructorOptions): typeof chalk;
export let enabled: boolean;
export let level: Level;
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 gray;
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;
}

40
types/test.ts Normal file
View file

@ -0,0 +1,40 @@
import chalk from '..';
chalk.underline('foo');
chalk.red('foo');
chalk.bgRed('foo');
const name = 'Josh';
chalk`Hello {bold.red ${name}}`;
chalk.red`foo`;
chalk.underline`foo`;
chalk`foo`;
chalk.red.bgGreen.underline('foo');
chalk.underline.red.bgGreen('foo');
chalk.grey('foo');
chalk.constructor({level: 1});
const ctx = chalk.constructor({level: chalk.Level.TrueColor });
ctx('foo');
ctx.red('foo');
ctx`foo`;
chalk.enabled = true;
chalk.level = 1;
chalk.level = chalk.Level.Extended;
chalk.level === chalk.Level.Extended;
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
}
}