index.cjs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var tty = require('tty');
  4. function _interopNamespace(e) {
  5. if (e && e.__esModule) return e;
  6. var n = Object.create(null);
  7. if (e) {
  8. Object.keys(e).forEach(function (k) {
  9. if (k !== 'default') {
  10. var d = Object.getOwnPropertyDescriptor(e, k);
  11. Object.defineProperty(n, k, d.get ? d : {
  12. enumerable: true,
  13. get: function () { return e[k]; }
  14. });
  15. }
  16. });
  17. }
  18. n["default"] = e;
  19. return Object.freeze(n);
  20. }
  21. var tty__namespace = /*#__PURE__*/_interopNamespace(tty);
  22. const env = process.env || {};
  23. const argv = process.argv || [];
  24. const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
  25. const isForced = "FORCE_COLOR" in env || argv.includes("--color");
  26. const isWindows = process.platform === "win32";
  27. const isCompatibleTerminal =
  28. tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && env.TERM !== "dumb";
  29. const isCI =
  30. "CI" in env &&
  31. ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
  32. const isColorSupported =
  33. !isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI);
  34. const replaceClose = (
  35. index,
  36. string,
  37. close,
  38. replace,
  39. head = string.substring(0, index) + replace,
  40. tail = string.substring(index + close.length),
  41. next = tail.indexOf(close)
  42. ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
  43. const clearBleed = (index, string, open, close, replace) =>
  44. index < 0
  45. ? open + string + close
  46. : open + replaceClose(index, string, close, replace) + close;
  47. const filterEmpty =
  48. (open, close, replace = open, at = open.length + 1) =>
  49. (string) =>
  50. string || !(string === "" || string === undefined)
  51. ? clearBleed(
  52. ("" + string).indexOf(close, at),
  53. string,
  54. open,
  55. close,
  56. replace
  57. )
  58. : "";
  59. const init = (open, close, replace) =>
  60. filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
  61. const colors = {
  62. reset: init(0, 0),
  63. bold: init(1, 22, "\x1b[22m\x1b[1m"),
  64. dim: init(2, 22, "\x1b[22m\x1b[2m"),
  65. italic: init(3, 23),
  66. underline: init(4, 24),
  67. inverse: init(7, 27),
  68. hidden: init(8, 28),
  69. strikethrough: init(9, 29),
  70. black: init(30, 39),
  71. red: init(31, 39),
  72. green: init(32, 39),
  73. yellow: init(33, 39),
  74. blue: init(34, 39),
  75. magenta: init(35, 39),
  76. cyan: init(36, 39),
  77. white: init(37, 39),
  78. gray: init(90, 39),
  79. bgBlack: init(40, 49),
  80. bgRed: init(41, 49),
  81. bgGreen: init(42, 49),
  82. bgYellow: init(43, 49),
  83. bgBlue: init(44, 49),
  84. bgMagenta: init(45, 49),
  85. bgCyan: init(46, 49),
  86. bgWhite: init(47, 49),
  87. blackBright: init(90, 39),
  88. redBright: init(91, 39),
  89. greenBright: init(92, 39),
  90. yellowBright: init(93, 39),
  91. blueBright: init(94, 39),
  92. magentaBright: init(95, 39),
  93. cyanBright: init(96, 39),
  94. whiteBright: init(97, 39),
  95. bgBlackBright: init(100, 49),
  96. bgRedBright: init(101, 49),
  97. bgGreenBright: init(102, 49),
  98. bgYellowBright: init(103, 49),
  99. bgBlueBright: init(104, 49),
  100. bgMagentaBright: init(105, 49),
  101. bgCyanBright: init(106, 49),
  102. bgWhiteBright: init(107, 49),
  103. };
  104. const none = (any) => any;
  105. const createColors = ({ useColor = isColorSupported } = {}) =>
  106. useColor
  107. ? colors
  108. : Object.keys(colors).reduce(
  109. (colors, key) => ({ ...colors, [key]: none }),
  110. {}
  111. );
  112. const {
  113. reset,
  114. bold,
  115. dim,
  116. italic,
  117. underline,
  118. inverse,
  119. hidden,
  120. strikethrough,
  121. black,
  122. red,
  123. green,
  124. yellow,
  125. blue,
  126. magenta,
  127. cyan,
  128. white,
  129. gray,
  130. bgBlack,
  131. bgRed,
  132. bgGreen,
  133. bgYellow,
  134. bgBlue,
  135. bgMagenta,
  136. bgCyan,
  137. bgWhite,
  138. blackBright,
  139. redBright,
  140. greenBright,
  141. yellowBright,
  142. blueBright,
  143. magentaBright,
  144. cyanBright,
  145. whiteBright,
  146. bgBlackBright,
  147. bgRedBright,
  148. bgGreenBright,
  149. bgYellowBright,
  150. bgBlueBright,
  151. bgMagentaBright,
  152. bgCyanBright,
  153. bgWhiteBright,
  154. } = createColors();
  155. exports.bgBlack = bgBlack;
  156. exports.bgBlackBright = bgBlackBright;
  157. exports.bgBlue = bgBlue;
  158. exports.bgBlueBright = bgBlueBright;
  159. exports.bgCyan = bgCyan;
  160. exports.bgCyanBright = bgCyanBright;
  161. exports.bgGreen = bgGreen;
  162. exports.bgGreenBright = bgGreenBright;
  163. exports.bgMagenta = bgMagenta;
  164. exports.bgMagentaBright = bgMagentaBright;
  165. exports.bgRed = bgRed;
  166. exports.bgRedBright = bgRedBright;
  167. exports.bgWhite = bgWhite;
  168. exports.bgWhiteBright = bgWhiteBright;
  169. exports.bgYellow = bgYellow;
  170. exports.bgYellowBright = bgYellowBright;
  171. exports.black = black;
  172. exports.blackBright = blackBright;
  173. exports.blue = blue;
  174. exports.blueBright = blueBright;
  175. exports.bold = bold;
  176. exports.createColors = createColors;
  177. exports.cyan = cyan;
  178. exports.cyanBright = cyanBright;
  179. exports.dim = dim;
  180. exports.gray = gray;
  181. exports.green = green;
  182. exports.greenBright = greenBright;
  183. exports.hidden = hidden;
  184. exports.inverse = inverse;
  185. exports.isColorSupported = isColorSupported;
  186. exports.italic = italic;
  187. exports.magenta = magenta;
  188. exports.magentaBright = magentaBright;
  189. exports.red = red;
  190. exports.redBright = redBright;
  191. exports.reset = reset;
  192. exports.strikethrough = strikethrough;
  193. exports.underline = underline;
  194. exports.white = white;
  195. exports.whiteBright = whiteBright;
  196. exports.yellow = yellow;
  197. exports.yellowBright = yellowBright;