feat: default export + typescript definitions
This commit is contained in:
parent
9c3d0f381c
commit
5d9f316842
4 changed files with 96 additions and 90 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 = Chalk(); // eslint-disable-line new-cap
|
||||||
module.exports.supportsColor = supportsColor;
|
module.exports.supportsColor = supportsColor;
|
||||||
|
module.exports.default = module.exports;
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
"matcha": "^0.7.0",
|
"matcha": "^0.7.0",
|
||||||
"nyc": "^11.0.2",
|
"nyc": "^11.0.2",
|
||||||
"resolve-from": "^3.0.0",
|
"resolve-from": "^3.0.0",
|
||||||
"typescript": "^2.4.1",
|
"typescript": "^2.5.2",
|
||||||
"xo": "*"
|
"xo": "*"
|
||||||
},
|
},
|
||||||
"types": "types/index.d.ts",
|
"types": "types/index.d.ts",
|
||||||
|
|
|
||||||
170
types/index.d.ts
vendored
170
types/index.d.ts
vendored
|
|
@ -1,87 +1,89 @@
|
||||||
// Type definitions for Chalk
|
// Type definitions for Chalk
|
||||||
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
|
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
|
||||||
|
export const enum Level {
|
||||||
export default chalk;
|
None = 0,
|
||||||
|
Basic = 1,
|
||||||
declare function chalk(...text: string[]): string;
|
Extended = 2,
|
||||||
declare function chalk(text: TemplateStringsArray, ...placeholders: string[]): string;
|
TrueColor = 3
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import chalk from '..';
|
import chalk, { Level } from '..';
|
||||||
|
|
||||||
chalk.underline('foo');
|
chalk.underline('foo');
|
||||||
chalk.red('foo');
|
chalk.red('foo');
|
||||||
|
|
@ -17,20 +17,23 @@ chalk.underline.red.bgGreen('foo');
|
||||||
chalk.grey('foo');
|
chalk.grey('foo');
|
||||||
|
|
||||||
chalk.constructor({level: 1});
|
chalk.constructor({level: 1});
|
||||||
const ctx = chalk.constructor({level: chalk.Level.TrueColor });
|
const ctx = chalk.constructor({level: Level.TrueColor });
|
||||||
ctx('foo');
|
ctx('foo');
|
||||||
ctx.red('foo');
|
ctx.red('foo');
|
||||||
ctx`foo`;
|
ctx`foo`;
|
||||||
|
|
||||||
chalk.enabled = true;
|
chalk.enabled = true;
|
||||||
chalk.level = 1;
|
chalk.level = 1;
|
||||||
chalk.level = chalk.Level.Extended;
|
chalk.level = Level.Extended;
|
||||||
|
|
||||||
chalk.level === chalk.Level.Extended;
|
chalk.level === Level.Extended;
|
||||||
|
|
||||||
chalk.enabled;
|
chalk.enabled;
|
||||||
chalk.supportsColor;
|
|
||||||
chalk.level;
|
chalk.level;
|
||||||
|
chalk.supportsColor.level;
|
||||||
|
chalk.supportsColor.has16m;
|
||||||
|
chalk.supportsColor.has256;
|
||||||
|
chalk.supportsColor.hasBasic;
|
||||||
|
|
||||||
chalk.keyword('orange').bgBlue('foo');
|
chalk.keyword('orange').bgBlue('foo');
|
||||||
chalk.hex('#123456').bgBlue('foo');
|
chalk.hex('#123456').bgBlue('foo');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue