forked from orbit-oss/chalk
Add TypeScript definitions (#207)
This commit is contained in:
parent
5e6d5fda44
commit
f653b061d6
5 changed files with 152 additions and 2 deletions
1
index.js
1
index.js
|
|
@ -218,3 +218,4 @@ Object.defineProperties(Chalk.prototype, styles);
|
|||
|
||||
module.exports = Chalk(); // eslint-disable-line new-cap
|
||||
module.exports.supportsColor = supportsColor;
|
||||
module.exports.default = module.exports; // For TypeScript
|
||||
|
|
|
|||
|
|
@ -8,13 +8,14 @@
|
|||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && nyc ava",
|
||||
"test": "xo && tsc --project types && nyc ava",
|
||||
"bench": "matcha benchmark.js",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"templates.js"
|
||||
"templates.js",
|
||||
"types/index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"color",
|
||||
|
|
@ -52,8 +53,10 @@
|
|||
"matcha": "^0.7.0",
|
||||
"nyc": "^11.0.2",
|
||||
"resolve-from": "^3.0.0",
|
||||
"typescript": "^2.5.3",
|
||||
"xo": "*"
|
||||
},
|
||||
"types": "types/index.d.ts",
|
||||
"xo": {
|
||||
"envs": [
|
||||
"node",
|
||||
|
|
|
|||
90
types/index.d.ts
vendored
Normal file
90
types/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
// Type definitions for Chalk
|
||||
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
|
||||
|
||||
export const enum Level {
|
||||
None = 0,
|
||||
Basic = 1,
|
||||
Ansi256 = 2,
|
||||
TrueColor = 3
|
||||
}
|
||||
|
||||
export interface ChalkOptions {
|
||||
enabled?: boolean;
|
||||
level?: Level;
|
||||
}
|
||||
|
||||
export interface Chalk {
|
||||
new (options?: ChalkOptions): Chalk;
|
||||
(options?: ChalkOptions): Chalk;
|
||||
(...text: string[]): string;
|
||||
(text: TemplateStringsArray, ...placeholders: string[]): string;
|
||||
constructor: Chalk;
|
||||
enabled: boolean;
|
||||
level: Level;
|
||||
supportsColor: {
|
||||
level: Level;
|
||||
hasBasic: boolean;
|
||||
has256: boolean;
|
||||
has16m: boolean;
|
||||
};
|
||||
rgb(r: number, g: number, b: number): Chalk;
|
||||
hsl(h: number, s: number, l: number): Chalk;
|
||||
hsv(h: number, s: number, v: number): Chalk;
|
||||
hwb(h: number, w: number, b: number): Chalk;
|
||||
bgHex(color: string): Chalk;
|
||||
bgKeyword(color: string): Chalk;
|
||||
bgRgb(r: number, g: number, b: number): Chalk;
|
||||
bgHsl(h: number, s: number, l: number): Chalk;
|
||||
bgHsv(h: number, s: number, v: number): Chalk;
|
||||
bgHwb(h: number, w: number, b: number): Chalk;
|
||||
hex(color: string): Chalk;
|
||||
keyword(color: string): Chalk;
|
||||
|
||||
reset: Chalk;
|
||||
bold: Chalk;
|
||||
dim: Chalk;
|
||||
italic: Chalk;
|
||||
underline: Chalk;
|
||||
inverse: Chalk;
|
||||
hidden: Chalk;
|
||||
strikethrough: Chalk;
|
||||
|
||||
black: Chalk;
|
||||
red: Chalk;
|
||||
green: Chalk;
|
||||
yellow: Chalk;
|
||||
blue: Chalk;
|
||||
magenta: Chalk;
|
||||
cyan: Chalk;
|
||||
white: Chalk;
|
||||
gray: Chalk;
|
||||
grey: Chalk;
|
||||
blackBright: Chalk;
|
||||
redBright: Chalk;
|
||||
greenBright: Chalk;
|
||||
yellowBright: Chalk;
|
||||
blueBright: Chalk;
|
||||
magentaBright: Chalk;
|
||||
cyanBright: Chalk;
|
||||
whiteBright: Chalk;
|
||||
|
||||
bgBlack: Chalk;
|
||||
bgRed: Chalk;
|
||||
bgGreen: Chalk;
|
||||
bgYellow: Chalk;
|
||||
bgBlue: Chalk;
|
||||
bgMagenta: Chalk;
|
||||
bgCyan: Chalk;
|
||||
bgWhite: Chalk;
|
||||
bgBlackBright: Chalk;
|
||||
bgRedBright: Chalk;
|
||||
bgGreenBright: Chalk;
|
||||
bgYellowBright: Chalk;
|
||||
bgBlueBright: Chalk;
|
||||
bgMagentaBright: Chalk;
|
||||
bgCyanBright: Chalk;
|
||||
bgWhiteBright: Chalk;
|
||||
}
|
||||
|
||||
declare function chalk (): any;
|
||||
export default chalk as Chalk;
|
||||
47
types/test.ts
Normal file
47
types/test.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import chalk, {Level} 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: Level.TrueColor });
|
||||
ctx('foo');
|
||||
ctx.red('foo');
|
||||
ctx`foo`;
|
||||
|
||||
chalk.enabled = true;
|
||||
chalk.level = 1;
|
||||
chalk.level = Level.Ansi256;
|
||||
|
||||
chalk.level === Level.Ansi256;
|
||||
|
||||
let chalkInstance = new chalk();
|
||||
chalkInstance = new chalk.constructor();
|
||||
chalkInstance = chalk.constructor();
|
||||
|
||||
chalk.enabled;
|
||||
chalk.level;
|
||||
chalk.supportsColor.level;
|
||||
chalk.supportsColor.has16m;
|
||||
chalk.supportsColor.has256;
|
||||
chalk.supportsColor.hasBasic;
|
||||
|
||||
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
9
types/tsconfig.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noEmit": true,
|
||||
"allowJs": true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue