index.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. // TODO: Make it this when TS suports that.
  2. // import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles';
  3. // import {ColorInfo, ColorSupportLevel} from '#supports-color';
  4. import {
  5. ModifierName,
  6. ForegroundColorName,
  7. BackgroundColorName,
  8. ColorName,
  9. } from './vendor/ansi-styles/index.js';
  10. import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
  11. export interface Options {
  12. /**
  13. Specify the color support for Chalk.
  14. By default, color support is automatically detected based on the environment.
  15. Levels:
  16. - `0` - All colors disabled.
  17. - `1` - Basic 16 colors support.
  18. - `2` - ANSI 256 colors support.
  19. - `3` - Truecolor 16 million colors support.
  20. */
  21. readonly level?: ColorSupportLevel;
  22. }
  23. /**
  24. Return a new Chalk instance.
  25. */
  26. export const Chalk: new (options?: Options) => ChalkInstance; // eslint-disable-line @typescript-eslint/naming-convention
  27. export interface ChalkInstance {
  28. (...text: unknown[]): string;
  29. /**
  30. The color support for Chalk.
  31. By default, color support is automatically detected based on the environment.
  32. Levels:
  33. - `0` - All colors disabled.
  34. - `1` - Basic 16 colors support.
  35. - `2` - ANSI 256 colors support.
  36. - `3` - Truecolor 16 million colors support.
  37. */
  38. level: ColorSupportLevel;
  39. /**
  40. Use RGB values to set text color.
  41. @example
  42. ```
  43. import chalk from 'chalk';
  44. chalk.rgb(222, 173, 237);
  45. ```
  46. */
  47. rgb: (red: number, green: number, blue: number) => this;
  48. /**
  49. Use HEX value to set text color.
  50. @param color - Hexadecimal value representing the desired color.
  51. @example
  52. ```
  53. import chalk from 'chalk';
  54. chalk.hex('#DEADED');
  55. ```
  56. */
  57. hex: (color: string) => this;
  58. /**
  59. Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
  60. @example
  61. ```
  62. import chalk from 'chalk';
  63. chalk.ansi256(201);
  64. ```
  65. */
  66. ansi256: (index: number) => this;
  67. /**
  68. Use RGB values to set background color.
  69. @example
  70. ```
  71. import chalk from 'chalk';
  72. chalk.bgRgb(222, 173, 237);
  73. ```
  74. */
  75. bgRgb: (red: number, green: number, blue: number) => this;
  76. /**
  77. Use HEX value to set background color.
  78. @param color - Hexadecimal value representing the desired color.
  79. @example
  80. ```
  81. import chalk from 'chalk';
  82. chalk.bgHex('#DEADED');
  83. ```
  84. */
  85. bgHex: (color: string) => this;
  86. /**
  87. Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
  88. @example
  89. ```
  90. import chalk from 'chalk';
  91. chalk.bgAnsi256(201);
  92. ```
  93. */
  94. bgAnsi256: (index: number) => this;
  95. /**
  96. Modifier: Reset the current style.
  97. */
  98. readonly reset: this;
  99. /**
  100. Modifier: Make the text bold.
  101. */
  102. readonly bold: this;
  103. /**
  104. Modifier: Make the text have lower opacity.
  105. */
  106. readonly dim: this;
  107. /**
  108. Modifier: Make the text italic. *(Not widely supported)*
  109. */
  110. readonly italic: this;
  111. /**
  112. Modifier: Put a horizontal line below the text. *(Not widely supported)*
  113. */
  114. readonly underline: this;
  115. /**
  116. Modifier: Put a horizontal line above the text. *(Not widely supported)*
  117. */
  118. readonly overline: this;
  119. /**
  120. Modifier: Invert background and foreground colors.
  121. */
  122. readonly inverse: this;
  123. /**
  124. Modifier: Print the text but make it invisible.
  125. */
  126. readonly hidden: this;
  127. /**
  128. Modifier: Puts a horizontal line through the center of the text. *(Not widely supported)*
  129. */
  130. readonly strikethrough: this;
  131. /**
  132. Modifier: Print the text only when Chalk has a color level above zero.
  133. Can be useful for things that are purely cosmetic.
  134. */
  135. readonly visible: this;
  136. readonly black: this;
  137. readonly red: this;
  138. readonly green: this;
  139. readonly yellow: this;
  140. readonly blue: this;
  141. readonly magenta: this;
  142. readonly cyan: this;
  143. readonly white: this;
  144. /*
  145. Alias for `blackBright`.
  146. */
  147. readonly gray: this;
  148. /*
  149. Alias for `blackBright`.
  150. */
  151. readonly grey: this;
  152. readonly blackBright: this;
  153. readonly redBright: this;
  154. readonly greenBright: this;
  155. readonly yellowBright: this;
  156. readonly blueBright: this;
  157. readonly magentaBright: this;
  158. readonly cyanBright: this;
  159. readonly whiteBright: this;
  160. readonly bgBlack: this;
  161. readonly bgRed: this;
  162. readonly bgGreen: this;
  163. readonly bgYellow: this;
  164. readonly bgBlue: this;
  165. readonly bgMagenta: this;
  166. readonly bgCyan: this;
  167. readonly bgWhite: this;
  168. /*
  169. Alias for `bgBlackBright`.
  170. */
  171. readonly bgGray: this;
  172. /*
  173. Alias for `bgBlackBright`.
  174. */
  175. readonly bgGrey: this;
  176. readonly bgBlackBright: this;
  177. readonly bgRedBright: this;
  178. readonly bgGreenBright: this;
  179. readonly bgYellowBright: this;
  180. readonly bgBlueBright: this;
  181. readonly bgMagentaBright: this;
  182. readonly bgCyanBright: this;
  183. readonly bgWhiteBright: this;
  184. }
  185. /**
  186. Main Chalk object that allows to chain styles together.
  187. Call the last one as a method with a string argument.
  188. Order doesn't matter, and later styles take precedent in case of a conflict.
  189. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
  190. */
  191. declare const chalk: ChalkInstance;
  192. export const supportsColor: ColorInfo;
  193. export const chalkStderr: typeof chalk;
  194. export const supportsColorStderr: typeof supportsColor;
  195. export {
  196. ModifierName, ForegroundColorName, BackgroundColorName, ColorName,
  197. modifierNames, foregroundColorNames, backgroundColorNames, colorNames,
  198. // } from '#ansi-styles';
  199. } from './vendor/ansi-styles/index.js';
  200. export {
  201. ColorInfo,
  202. ColorSupport,
  203. ColorSupportLevel,
  204. // } from '#supports-color';
  205. } from './vendor/supports-color/index.js';
  206. // TODO: Remove these aliases in the next major version
  207. /**
  208. @deprecated Use `ModifierName` instead.
  209. Basic modifier names.
  210. */
  211. export type Modifiers = ModifierName;
  212. /**
  213. @deprecated Use `ForegroundColorName` instead.
  214. Basic foreground color names.
  215. [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
  216. */
  217. export type ForegroundColor = ForegroundColorName;
  218. /**
  219. @deprecated Use `BackgroundColorName` instead.
  220. Basic background color names.
  221. [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
  222. */
  223. export type BackgroundColor = BackgroundColorName;
  224. /**
  225. @deprecated Use `ColorName` instead.
  226. Basic color names. The combination of foreground and background color names.
  227. [More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
  228. */
  229. export type Color = ColorName;
  230. /**
  231. @deprecated Use `modifierNames` instead.
  232. Basic modifier names.
  233. */
  234. export const modifiers: readonly Modifiers[];
  235. /**
  236. @deprecated Use `foregroundColorNames` instead.
  237. Basic foreground color names.
  238. */
  239. export const foregroundColors: readonly ForegroundColor[];
  240. /**
  241. @deprecated Use `backgroundColorNames` instead.
  242. Basic background color names.
  243. */
  244. export const backgroundColors: readonly BackgroundColor[];
  245. /**
  246. @deprecated Use `colorNames` instead.
  247. Basic color names. The combination of foreground and background color names.
  248. */
  249. export const colors: readonly Color[];
  250. export default chalk;