Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2021-04-17 18:03:12 +12:00
parent 5dbc9d54d6
commit 427ea57355
No known key found for this signature in database
GPG key ID: 1C6A99DFA9D306FC
2 changed files with 67 additions and 81 deletions

140
index.d.ts vendored
View file

@ -93,7 +93,7 @@ export interface Options {
/** /**
Return a new Chalk instance. Return a new Chalk instance.
*/ */
export type ChalkClass = new (options?: Options) => ChalkInstance; export const Chalk: new (options?: Options) => ChalkInstance;
/** /**
Detect whether the terminal supports color. Detect whether the terminal supports color.
@ -150,11 +150,6 @@ interface ChalkFunction {
} }
export interface ChalkInstance extends ChalkFunction { export interface ChalkInstance extends ChalkFunction {
/**
Return a new Chalk instance.
*/
Chalk: ChalkClass;
/** /**
The color support for Chalk. The color support for Chalk.
@ -180,7 +175,7 @@ export interface ChalkInstance extends ChalkFunction {
chalk.hex('#DEADED'); chalk.hex('#DEADED');
``` ```
*/ */
hex: (color: string) => ChalkInstance; hex: (color: string) => this;
/** /**
Use keyword color value to set text color. Use keyword color value to set text color.
@ -194,27 +189,27 @@ export interface ChalkInstance extends ChalkFunction {
chalk.keyword('orange'); chalk.keyword('orange');
``` ```
*/ */
keyword: (color: string) => ChalkInstance; keyword: (color: string) => this;
/** /**
Use RGB values to set text color. Use RGB values to set text color.
*/ */
rgb: (red: number, green: number, blue: number) => ChalkInstance; rgb: (red: number, green: number, blue: number) => this;
/** /**
Use HSL values to set text color. Use HSL values to set text color.
*/ */
hsl: (hue: number, saturation: number, lightness: number) => ChalkInstance; hsl: (hue: number, saturation: number, lightness: number) => this;
/** /**
Use HSV values to set text color. Use HSV values to set text color.
*/ */
hsv: (hue: number, saturation: number, value: number) => ChalkInstance; hsv: (hue: number, saturation: number, value: number) => this;
/** /**
Use HWB values to set text color. Use HWB values to set text color.
*/ */
hwb: (hue: number, whiteness: number, blackness: number) => ChalkInstance; hwb: (hue: number, whiteness: number, blackness: number) => this;
/** /**
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color. Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
@ -222,12 +217,12 @@ export interface ChalkInstance extends ChalkFunction {
30 <= code && code < 38 || 90 <= code && code < 98 30 <= code && code < 38 || 90 <= code && code < 98
For example, 31 for red, 91 for redBright. For example, 31 for red, 91 for redBright.
*/ */
ansi: (code: number) => ChalkInstance; ansi: (code: number) => this;
/** /**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color. Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
*/ */
ansi256: (index: number) => ChalkInstance; ansi256: (index: number) => this;
/** /**
Use HEX value to set background color. Use HEX value to set background color.
@ -241,7 +236,7 @@ export interface ChalkInstance extends ChalkFunction {
chalk.bgHex('#DEADED'); chalk.bgHex('#DEADED');
``` ```
*/ */
bgHex: (color: string) => ChalkInstance; bgHex: (color: string) => this;
/** /**
Use keyword color value to set background color. Use keyword color value to set background color.
@ -255,27 +250,27 @@ export interface ChalkInstance extends ChalkFunction {
chalk.bgKeyword('orange'); chalk.bgKeyword('orange');
``` ```
*/ */
bgKeyword: (color: string) => ChalkInstance; bgKeyword: (color: string) => this;
/** /**
Use RGB values to set background color. Use RGB values to set background color.
*/ */
bgRgb: (red: number, green: number, blue: number) => ChalkInstance; bgRgb: (red: number, green: number, blue: number) => this;
/** /**
Use HSL values to set background color. Use HSL values to set background color.
*/ */
bgHsl: (hue: number, saturation: number, lightness: number) => ChalkInstance; bgHsl: (hue: number, saturation: number, lightness: number) => this;
/** /**
Use HSV values to set background color. Use HSV values to set background color.
*/ */
bgHsv: (hue: number, saturation: number, value: number) => ChalkInstance; bgHsv: (hue: number, saturation: number, value: number) => this;
/** /**
Use HWB values to set background color. Use HWB values to set background color.
*/ */
bgHwb: (hue: number, whiteness: number, blackness: number) => ChalkInstance; bgHwb: (hue: number, whiteness: number, blackness: number) => this;
/** /**
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color. Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
@ -284,114 +279,114 @@ export interface ChalkInstance extends ChalkFunction {
For example, 31 for red, 91 for redBright. For example, 31 for red, 91 for redBright.
Use the foreground code, not the background code (for example, not 41, nor 101). Use the foreground code, not the background code (for example, not 41, nor 101).
*/ */
bgAnsi: (code: number) => ChalkInstance; bgAnsi: (code: number) => this;
/** /**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color. Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
*/ */
bgAnsi256: (index: number) => ChalkInstance; bgAnsi256: (index: number) => this;
/** /**
Modifier: Resets the current color chain. Modifier: Resets the current color chain.
*/ */
readonly reset: ChalkInstance; readonly reset: this;
/** /**
Modifier: Make text bold. Modifier: Make text bold.
*/ */
readonly bold: ChalkInstance; readonly bold: this;
/** /**
Modifier: Emitting only a small amount of light. Modifier: Emitting only a small amount of light.
*/ */
readonly dim: ChalkInstance; readonly dim: this;
/** /**
Modifier: Make text italic. (Not widely supported) Modifier: Make text italic. (Not widely supported)
*/ */
readonly italic: ChalkInstance; readonly italic: this;
/** /**
Modifier: Make text underline. (Not widely supported) Modifier: Make text underline. (Not widely supported)
*/ */
readonly underline: ChalkInstance; readonly underline: this;
/** /**
Modifier: Inverse background and foreground colors. Modifier: Inverse background and foreground colors.
*/ */
readonly inverse: ChalkInstance; readonly inverse: this;
/** /**
Modifier: Prints the text, but makes it invisible. Modifier: Prints the text, but makes it invisible.
*/ */
readonly hidden: ChalkInstance; readonly hidden: this;
/** /**
Modifier: Puts a horizontal line through the center of the text. (Not widely supported) Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
*/ */
readonly strikethrough: ChalkInstance; readonly strikethrough: this;
/** /**
Modifier: Prints the text only when Chalk has a color support level > 0. Modifier: Prints the text only when Chalk has a color support level > 0.
Can be useful for things that are purely cosmetic. Can be useful for things that are purely cosmetic.
*/ */
readonly visible: ChalkInstance; readonly visible: this;
readonly black: ChalkInstance; readonly black: this;
readonly red: ChalkInstance; readonly red: this;
readonly green: ChalkInstance; readonly green: this;
readonly yellow: ChalkInstance; readonly yellow: this;
readonly blue: ChalkInstance; readonly blue: this;
readonly magenta: ChalkInstance; readonly magenta: this;
readonly cyan: ChalkInstance; readonly cyan: this;
readonly white: ChalkInstance; readonly white: this;
/* /*
Alias for `blackBright`. Alias for `blackBright`.
*/ */
readonly gray: ChalkInstance; readonly gray: this;
/* /*
Alias for `blackBright`. Alias for `blackBright`.
*/ */
readonly grey: ChalkInstance; readonly grey: this;
readonly blackBright: ChalkInstance; readonly blackBright: this;
readonly redBright: ChalkInstance; readonly redBright: this;
readonly greenBright: ChalkInstance; readonly greenBright: this;
readonly yellowBright: ChalkInstance; readonly yellowBright: this;
readonly blueBright: ChalkInstance; readonly blueBright: this;
readonly magentaBright: ChalkInstance; readonly magentaBright: this;
readonly cyanBright: ChalkInstance; readonly cyanBright: this;
readonly whiteBright: ChalkInstance; readonly whiteBright: this;
readonly bgBlack: ChalkInstance; readonly bgBlack: this;
readonly bgRed: ChalkInstance; readonly bgRed: this;
readonly bgGreen: ChalkInstance; readonly bgGreen: this;
readonly bgYellow: ChalkInstance; readonly bgYellow: this;
readonly bgBlue: ChalkInstance; readonly bgBlue: this;
readonly bgMagenta: ChalkInstance; readonly bgMagenta: this;
readonly bgCyan: ChalkInstance; readonly bgCyan: this;
readonly bgWhite: ChalkInstance; readonly bgWhite: this;
/* /*
Alias for `bgBlackBright`. Alias for `bgBlackBright`.
*/ */
readonly bgGray: ChalkInstance; readonly bgGray: this;
/* /*
Alias for `bgBlackBright`. Alias for `bgBlackBright`.
*/ */
readonly bgGrey: ChalkInstance; readonly bgGrey: this;
readonly bgBlackBright: ChalkInstance; readonly bgBlackBright: this;
readonly bgRedBright: ChalkInstance; readonly bgRedBright: this;
readonly bgGreenBright: ChalkInstance; readonly bgGreenBright: this;
readonly bgYellowBright: ChalkInstance; readonly bgYellowBright: this;
readonly bgBlueBright: ChalkInstance; readonly bgBlueBright: this;
readonly bgMagentaBright: ChalkInstance; readonly bgMagentaBright: this;
readonly bgCyanBright: ChalkInstance; readonly bgCyanBright: this;
readonly bgWhiteBright: ChalkInstance; readonly bgWhiteBright: this;
} }
/** /**
@ -405,14 +400,7 @@ This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
*/ */
declare const chalk: ChalkInstance & ChalkFunction; declare const chalk: ChalkInstance & ChalkFunction;
declare const supportsColor: ColorSupport | false; export const supportsColor: ColorSupport | false;
declare const chalkStderr: ChalkInstance & {supportsColor: ColorSupport | false}; export const chalkStderr: typeof chalk & {supportsColor: typeof supportsColor};
declare const Chalk: ChalkClass;
export {
supportsColor,
chalkStderr,
Chalk
};
export default chalk; export default chalk;

View file

@ -29,7 +29,7 @@ const applyOptions = (object, options = {}) => {
object.level = options.level === undefined ? colorLevel : options.level; object.level = options.level === undefined ? colorLevel : options.level;
}; };
class Chalk { export class Chalk {
constructor(options) { constructor(options) {
// eslint-disable-next-line no-constructor-return // eslint-disable-next-line no-constructor-return
return chalkFactory(options); return chalkFactory(options);
@ -212,13 +212,11 @@ const chalkTag = (chalk, ...strings) => {
Object.defineProperties(createChalk.prototype, styles); Object.defineProperties(createChalk.prototype, styles);
const chalk = createChalk(); const chalk = createChalk();
const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0}); export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
chalkStderr.supportsColor = stderrColor; chalkStderr.supportsColor = stderrColor;
export { export {
stdoutColor as supportsColor, stdoutColor as supportsColor
chalkStderr,
Chalk
}; };
export default chalk; export default chalk;