utils.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. type BoxBorderStyle = {
  2. /**
  3. * Top left corner
  4. * @example `┌`
  5. * @example `╔`
  6. * @example `╓`
  7. */
  8. tl: string;
  9. /**
  10. * Top right corner
  11. * @example `┐`
  12. * @example `╗`
  13. * @example `╖`
  14. */
  15. tr: string;
  16. /**
  17. * Bottom left corner
  18. * @example `└`
  19. * @example `╚`
  20. * @example `╙`
  21. */
  22. bl: string;
  23. /**
  24. * Bottom right corner
  25. * @example `┘`
  26. * @example `╝`
  27. * @example `╜`
  28. */
  29. br: string;
  30. /**
  31. * Horizontal line
  32. * @example `─`
  33. * @example `═`
  34. * @example `─`
  35. */
  36. h: string;
  37. /**
  38. * Vertical line
  39. * @example `│`
  40. * @example `║`
  41. * @example `║`
  42. */
  43. v: string;
  44. };
  45. declare const boxStylePresets: Record<string, BoxBorderStyle>;
  46. type BoxStyle = {
  47. /**
  48. * The border color
  49. * @default 'white'
  50. */
  51. borderColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
  52. /**
  53. * The border style
  54. * @default 'solid'
  55. * @example 'single-double-rounded'
  56. * @example
  57. * ```ts
  58. * {
  59. * tl: '┌',
  60. * tr: '┐',
  61. * bl: '└',
  62. * br: '┘',
  63. * h: '─',
  64. * v: '│',
  65. * }
  66. * ```
  67. */
  68. borderStyle: BoxBorderStyle | keyof typeof boxStylePresets;
  69. /**
  70. * The vertical alignment of the text
  71. * @default 'center'
  72. */
  73. valign: "top" | "center" | "bottom";
  74. /**
  75. * The padding of the box
  76. * @default 2
  77. */
  78. padding: number;
  79. /**
  80. * The left margin of the box
  81. * @default 1
  82. */
  83. marginLeft: number;
  84. /**
  85. * The top margin of the box
  86. * @default 1
  87. */
  88. marginTop: number;
  89. /**
  90. * The top margin of the box
  91. * @default 1
  92. */
  93. marginBottom: number;
  94. };
  95. /**
  96. * The border options of the box
  97. */
  98. type BoxOpts = {
  99. /**
  100. * Title that will be displayed on top of the box
  101. * @example 'Hello World'
  102. * @example 'Hello {name}'
  103. */
  104. title?: string;
  105. style?: Partial<BoxStyle>;
  106. };
  107. declare function box(text: string, _opts?: BoxOpts): string;
  108. /**
  109. * Based on https://github.com/jorgebucaran/colorette
  110. * Read LICENSE file for more information
  111. * https://github.com/jorgebucaran/colorette/blob/20fc196d07d0f87c61e0256eadd7831c79b24108/index.js
  112. */
  113. declare const colorDefs: {
  114. reset: (string: string) => string;
  115. bold: (string: string) => string;
  116. dim: (string: string) => string;
  117. italic: (string: string) => string;
  118. underline: (string: string) => string;
  119. inverse: (string: string) => string;
  120. hidden: (string: string) => string;
  121. strikethrough: (string: string) => string;
  122. black: (string: string) => string;
  123. red: (string: string) => string;
  124. green: (string: string) => string;
  125. yellow: (string: string) => string;
  126. blue: (string: string) => string;
  127. magenta: (string: string) => string;
  128. cyan: (string: string) => string;
  129. white: (string: string) => string;
  130. gray: (string: string) => string;
  131. bgBlack: (string: string) => string;
  132. bgRed: (string: string) => string;
  133. bgGreen: (string: string) => string;
  134. bgYellow: (string: string) => string;
  135. bgBlue: (string: string) => string;
  136. bgMagenta: (string: string) => string;
  137. bgCyan: (string: string) => string;
  138. bgWhite: (string: string) => string;
  139. blackBright: (string: string) => string;
  140. redBright: (string: string) => string;
  141. greenBright: (string: string) => string;
  142. yellowBright: (string: string) => string;
  143. blueBright: (string: string) => string;
  144. magentaBright: (string: string) => string;
  145. cyanBright: (string: string) => string;
  146. whiteBright: (string: string) => string;
  147. bgBlackBright: (string: string) => string;
  148. bgRedBright: (string: string) => string;
  149. bgGreenBright: (string: string) => string;
  150. bgYellowBright: (string: string) => string;
  151. bgBlueBright: (string: string) => string;
  152. bgMagentaBright: (string: string) => string;
  153. bgCyanBright: (string: string) => string;
  154. bgWhiteBright: (string: string) => string;
  155. };
  156. type ColorName = keyof typeof colorDefs;
  157. type ColorFunction = (text: string | number) => string;
  158. declare const colors: Record<"reset" | "bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright", ColorFunction>;
  159. declare function getColor(color: ColorName, fallback?: ColorName): ColorFunction;
  160. declare function colorize(color: ColorName, text: string | number): string;
  161. declare function stripAnsi(text: string): string;
  162. declare function centerAlign(str: string, len: number, space?: string): string;
  163. declare function rightAlign(str: string, len: number, space?: string): string;
  164. declare function leftAlign(str: string, len: number, space?: string): string;
  165. declare function align(alignment: "left" | "right" | "center", str: string, len: number, space?: string): string;
  166. export { BoxBorderStyle, BoxOpts, BoxStyle, ColorFunction, ColorName, align, box, centerAlign, colorize, colors, getColor, leftAlign, rightAlign, stripAnsi };