@cjser/chalk 5.6.2-cjser.2 → 6.0.0-cjser.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
- // packages/@cjser/chalk/source/index.js
29
+ // packages/@cjser/chalk.tmp-26-1785083112196/source/index.js
30
30
  var index_exports = {};
31
31
  __export(index_exports, {
32
32
  Chalk: () => Chalk,
@@ -41,15 +41,48 @@ __export(index_exports, {
41
41
  modifierNames: () => modifierNames,
42
42
  modifiers: () => modifierNames,
43
43
  supportsColor: () => stdoutColor,
44
- supportsColorStderr: () => stderrColor
44
+ supportsColorStderr: () => stderrColor,
45
+ underlineColorNames: () => underlineColorNames
45
46
  });
46
47
  module.exports = __toCommonJS(index_exports);
47
48
 
48
- // packages/@cjser/chalk/source/vendor/ansi-styles/index.js
49
+ // packages/@cjser/chalk.tmp-26-1785083112196/source/utilities.js
50
+ function stringReplaceAll(string, substring, postfix) {
51
+ let index = string.indexOf(substring);
52
+ if (index === -1) {
53
+ return string;
54
+ }
55
+ const substringLength = substring.length;
56
+ let endIndex = 0;
57
+ let returnValue = "";
58
+ do {
59
+ returnValue += string.slice(endIndex, index) + substring + postfix;
60
+ endIndex = index + substringLength;
61
+ index = string.indexOf(substring, endIndex);
62
+ } while (index !== -1);
63
+ returnValue += string.slice(endIndex);
64
+ return returnValue;
65
+ }
66
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
67
+ let endIndex = 0;
68
+ let returnValue = "";
69
+ do {
70
+ const isGotCR = string[index - 1] === "\r";
71
+ returnValue += string.slice(endIndex, isGotCR ? index - 1 : index) + prefix + (isGotCR ? "\r\n" : "\n") + postfix;
72
+ endIndex = index + 1;
73
+ index = string.indexOf("\n", endIndex);
74
+ } while (index !== -1);
75
+ returnValue += string.slice(endIndex);
76
+ return returnValue;
77
+ }
78
+
79
+ // packages/@cjser/chalk.tmp-26-1785083112196/source/vendor/ansi-styles/index.js
49
80
  var ANSI_BACKGROUND_OFFSET = 10;
81
+ var ANSI_UNDERLINE_OFFSET = 20;
50
82
  var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
51
83
  var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
52
84
  var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
85
+ var wrapUnderlineAnsi = (code) => `\x1B[58;5;${code < 90 ? code - 30 : code - 90 + 8}m`;
53
86
  var styles = {
54
87
  modifier: {
55
88
  reset: [0, 0],
@@ -58,6 +91,11 @@ var styles = {
58
91
  dim: [2, 22],
59
92
  italic: [3, 23],
60
93
  underline: [4, 24],
94
+ // Extended underline styles (`SGR 4:x` sub-parameters). Not in upstream `ansi-styles`.
95
+ underlineDouble: ["4:2", 24],
96
+ underlineCurly: ["4:3", 24],
97
+ underlineDotted: ["4:4", 24],
98
+ underlineDashed: ["4:5", 24],
61
99
  overline: [53, 55],
62
100
  inverse: [7, 27],
63
101
  hidden: [8, 28],
@@ -108,11 +146,36 @@ var styles = {
108
146
  bgMagentaBright: [105, 49],
109
147
  bgCyanBright: [106, 49],
110
148
  bgWhiteBright: [107, 49]
149
+ },
150
+ // Underline color (`SGR 58`/`59`). Not in upstream `ansi-styles`.
151
+ underlineColor: {
152
+ underlineBlack: ["58;5;0", 59],
153
+ underlineRed: ["58;5;1", 59],
154
+ underlineGreen: ["58;5;2", 59],
155
+ underlineYellow: ["58;5;3", 59],
156
+ underlineBlue: ["58;5;4", 59],
157
+ underlineMagenta: ["58;5;5", 59],
158
+ underlineCyan: ["58;5;6", 59],
159
+ underlineWhite: ["58;5;7", 59],
160
+ // Bright color
161
+ underlineBlackBright: ["58;5;8", 59],
162
+ underlineGray: ["58;5;8", 59],
163
+ // Alias of `underlineBlackBright`
164
+ underlineGrey: ["58;5;8", 59],
165
+ // Alias of `underlineBlackBright`
166
+ underlineRedBright: ["58;5;9", 59],
167
+ underlineGreenBright: ["58;5;10", 59],
168
+ underlineYellowBright: ["58;5;11", 59],
169
+ underlineBlueBright: ["58;5;12", 59],
170
+ underlineMagentaBright: ["58;5;13", 59],
171
+ underlineCyanBright: ["58;5;14", 59],
172
+ underlineWhiteBright: ["58;5;15", 59]
111
173
  }
112
174
  };
113
175
  var modifierNames = Object.keys(styles.modifier);
114
176
  var foregroundColorNames = Object.keys(styles.color);
115
177
  var backgroundColorNames = Object.keys(styles.bgColor);
178
+ var underlineColorNames = Object.keys(styles.underlineColor);
116
179
  var colorNames = [...foregroundColorNames, ...backgroundColorNames];
117
180
  function assembleStyles() {
118
181
  const codes = /* @__PURE__ */ new Map();
@@ -123,7 +186,7 @@ function assembleStyles() {
123
186
  close: `\x1B[${style[1]}m`
124
187
  };
125
188
  group[styleName] = styles[styleName];
126
- codes.set(style[0], style[1]);
189
+ codes.set(Number.parseInt(style[0], 10), style[1]);
127
190
  }
128
191
  Object.defineProperty(styles, groupName, {
129
192
  value: group,
@@ -136,12 +199,16 @@ function assembleStyles() {
136
199
  });
137
200
  styles.color.close = "\x1B[39m";
138
201
  styles.bgColor.close = "\x1B[49m";
202
+ styles.underlineColor.close = "\x1B[59m";
139
203
  styles.color.ansi = wrapAnsi16();
140
204
  styles.color.ansi256 = wrapAnsi256();
141
205
  styles.color.ansi16m = wrapAnsi16m();
142
206
  styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
143
207
  styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
144
208
  styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
209
+ styles.underlineColor.ansi = wrapUnderlineAnsi;
210
+ styles.underlineColor.ansi256 = wrapAnsi256(ANSI_UNDERLINE_OFFSET);
211
+ styles.underlineColor.ansi16m = wrapAnsi16m(ANSI_UNDERLINE_OFFSET);
145
212
  Object.defineProperties(styles, {
146
213
  rgbToAnsi256: {
147
214
  value(red, green, blue) {
@@ -160,7 +227,7 @@ function assembleStyles() {
160
227
  },
161
228
  hexToRgb: {
162
229
  value(hex) {
163
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
230
+ const matches = /[\da-f]{6}|[\da-f]{3}/i.exec(hex.toString(16));
164
231
  if (!matches) {
165
232
  return [0, 0, 0];
166
233
  }
@@ -170,7 +237,7 @@ function assembleStyles() {
170
237
  }
171
238
  const integer = Number.parseInt(colorString, 16);
172
239
  return [
173
- /* eslint-disable no-bitwise */
240
+ /* eslint-disable no-bitwise -- We need the speed */
174
241
  integer >> 16 & 255,
175
242
  integer >> 8 & 255,
176
243
  integer & 255
@@ -231,7 +298,7 @@ function assembleStyles() {
231
298
  var ansiStyles = assembleStyles();
232
299
  var ansi_styles_default = ansiStyles;
233
300
 
234
- // packages/@cjser/chalk/source/vendor/supports-color/index.js
301
+ // packages/@cjser/chalk.tmp-26-1785083112196/source/vendor/supports-color/index.js
235
302
  var import_node_process = __toESM(require("node:process"), 1);
236
303
  var import_node_os = __toESM(require("node:os"), 1);
237
304
  var import_node_tty = __toESM(require("node:tty"), 1);
@@ -248,16 +315,23 @@ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || has
248
315
  } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
249
316
  flagForceColor = 1;
250
317
  }
318
+ function hasNumericForceColor() {
319
+ return /^\d+$/.test(env.FORCE_COLOR);
320
+ }
251
321
  function envForceColor() {
252
- if ("FORCE_COLOR" in env) {
253
- if (env.FORCE_COLOR === "true") {
254
- return 1;
255
- }
256
- if (env.FORCE_COLOR === "false") {
257
- return 0;
258
- }
259
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
322
+ if (!("FORCE_COLOR" in env)) {
323
+ return;
324
+ }
325
+ if (env.FORCE_COLOR === "false") {
326
+ return 0;
327
+ }
328
+ if (env.FORCE_COLOR === "true" || env.FORCE_COLOR.length === 0) {
329
+ return 1;
330
+ }
331
+ if (!hasNumericForceColor()) {
332
+ return;
260
333
  }
334
+ return Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
261
335
  }
262
336
  function translateLevel(level) {
263
337
  if (level === 0) {
@@ -287,6 +361,9 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
287
361
  return 2;
288
362
  }
289
363
  }
364
+ if (forceColor !== void 0 && hasNumericForceColor()) {
365
+ return forceColor;
366
+ }
290
367
  if ("TF_BUILD" in env && "AGENT_NAME" in env) {
291
368
  return 1;
292
369
  }
@@ -314,7 +391,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
314
391
  return min;
315
392
  }
316
393
  if ("TEAMCITY_VERSION" in env) {
317
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
394
+ return /^(?:9\.0*[1-9]\d*\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
318
395
  }
319
396
  if (env.COLORTERM === "truecolor") {
320
397
  return 3;
@@ -329,7 +406,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
329
406
  return 3;
330
407
  }
331
408
  if ("TERM_PROGRAM" in env) {
332
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
409
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".", 1)[0], 10);
333
410
  switch (env.TERM_PROGRAM) {
334
411
  case "iTerm.app": {
335
412
  return version >= 3 ? 3 : 2;
@@ -339,7 +416,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
339
416
  }
340
417
  }
341
418
  }
342
- if (/-256(color)?$/i.test(env.TERM)) {
419
+ if (/-256(?:color)?$/i.test(env.TERM)) {
343
420
  return 2;
344
421
  }
345
422
  if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
@@ -363,54 +440,34 @@ var supportsColor = {
363
440
  };
364
441
  var supports_color_default = supportsColor;
365
442
 
366
- // packages/@cjser/chalk/source/utilities.js
367
- function stringReplaceAll(string, substring, replacer) {
368
- let index = string.indexOf(substring);
369
- if (index === -1) {
370
- return string;
371
- }
372
- const substringLength = substring.length;
373
- let endIndex = 0;
374
- let returnValue = "";
375
- do {
376
- returnValue += string.slice(endIndex, index) + substring + replacer;
377
- endIndex = index + substringLength;
378
- index = string.indexOf(substring, endIndex);
379
- } while (index !== -1);
380
- returnValue += string.slice(endIndex);
381
- return returnValue;
382
- }
383
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
384
- let endIndex = 0;
385
- let returnValue = "";
386
- do {
387
- const gotCR = string[index - 1] === "\r";
388
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
389
- endIndex = index + 1;
390
- index = string.indexOf("\n", endIndex);
391
- } while (index !== -1);
392
- returnValue += string.slice(endIndex);
393
- return returnValue;
394
- }
395
-
396
- // packages/@cjser/chalk/source/index.js
443
+ // packages/@cjser/chalk.tmp-26-1785083112196/source/index.js
397
444
  var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
398
445
  var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
399
446
  var STYLER = /* @__PURE__ */ Symbol("STYLER");
400
447
  var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
401
- var levelMapping = [
402
- "ansi",
403
- "ansi",
404
- "ansi256",
405
- "ansi16m"
406
- ];
448
+ var LEVEL = /* @__PURE__ */ Symbol("LEVEL");
407
449
  var styles2 = /* @__PURE__ */ Object.create(null);
450
+ var assertValidLevel = (level) => {
451
+ if (!Number.isSafeInteger(level) || level < 0 || level > 3) {
452
+ throw new Error("The `level` should be an integer from 0 to 3");
453
+ }
454
+ };
455
+ var levelDescriptor = {
456
+ enumerable: true,
457
+ get() {
458
+ return this[LEVEL];
459
+ },
460
+ set(level) {
461
+ assertValidLevel(level);
462
+ this[LEVEL] = level;
463
+ }
464
+ };
408
465
  var applyOptions = (object, options = {}) => {
409
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
410
- throw new Error("The `level` option should be an integer from 0 to 3");
466
+ if (options.level !== void 0) {
467
+ assertValidLevel(options.level);
411
468
  }
412
469
  const colorLevel = stdoutColor ? stdoutColor.level : 0;
413
- object.level = options.level === void 0 ? colorLevel : options.level;
470
+ object[LEVEL] = options.level === void 0 ? colorLevel : options.level;
414
471
  };
415
472
  var Chalk = class {
416
473
  constructor(options) {
@@ -443,56 +500,59 @@ styles2.visible = {
443
500
  return builder;
444
501
  }
445
502
  };
446
- var getModelAnsi = (model, level, type, ...arguments_) => {
503
+ var createModelConverters = (model, type) => {
504
+ const style = ansi_styles_default[type];
447
505
  if (model === "rgb") {
448
- if (level === "ansi16m") {
449
- return ansi_styles_default[type].ansi16m(...arguments_);
450
- }
451
- if (level === "ansi256") {
452
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
453
- }
454
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
506
+ const ansi2 = (red, green, blue) => style.ansi(ansi_styles_default.rgbToAnsi(red, green, blue));
507
+ const ansi256 = (red, green, blue) => style.ansi256(ansi_styles_default.rgbToAnsi256(red, green, blue));
508
+ return [ansi2, ansi2, ansi256, style.ansi16m];
455
509
  }
456
510
  if (model === "hex") {
457
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
511
+ const ansi2 = (hex) => style.ansi(ansi_styles_default.hexToAnsi(hex));
512
+ const ansi256 = (hex) => style.ansi256(ansi_styles_default.hexToAnsi256(hex));
513
+ return [ansi2, ansi2, ansi256, (hex) => style.ansi16m(...ansi_styles_default.hexToRgb(hex))];
458
514
  }
459
- return ansi_styles_default[type][model](...arguments_);
515
+ const ansi = (code) => style.ansi(ansi_styles_default.ansi256ToAnsi(code));
516
+ return [ansi, ansi, style.ansi256, style.ansi256];
460
517
  };
461
518
  var usedModels = ["rgb", "hex", "ansi256"];
462
519
  for (const model of usedModels) {
463
- styles2[model] = {
464
- get() {
465
- const { level } = this;
466
- return function(...arguments_) {
467
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
468
- return createBuilder(this, styler, this[IS_EMPTY]);
469
- };
470
- }
471
- };
472
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
473
- styles2[bgModel] = {
474
- get() {
475
- const { level } = this;
476
- return function(...arguments_) {
477
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
478
- return createBuilder(this, styler, this[IS_EMPTY]);
479
- };
480
- }
481
- };
520
+ const capitalizedModel = model[0].toUpperCase() + model.slice(1);
521
+ for (const [styleName, type] of [
522
+ [model, "color"],
523
+ ["bg" + capitalizedModel, "bgColor"],
524
+ ["underline" + capitalizedModel, "underlineColor"]
525
+ ]) {
526
+ const { close } = ansi_styles_default[type];
527
+ const converters = createModelConverters(model, type);
528
+ styles2[styleName] = {
529
+ get() {
530
+ const styleFunction = function(first, second, third) {
531
+ const open = converters[this.level](first, second, third);
532
+ return createBuilder(this, createStyler(open, close, this[STYLER]), this[IS_EMPTY]);
533
+ };
534
+ Object.defineProperty(this, styleName, { value: styleFunction });
535
+ return styleFunction;
536
+ }
537
+ };
538
+ }
482
539
  }
483
- var proto = Object.defineProperties(() => {
484
- }, {
485
- ...styles2,
486
- level: {
487
- enumerable: true,
488
- get() {
489
- return this[GENERATOR].level;
490
- },
491
- set(level) {
492
- this[GENERATOR].level = level;
540
+ var proto = Object.defineProperties(
541
+ () => {
542
+ },
543
+ {
544
+ ...styles2,
545
+ level: {
546
+ enumerable: true,
547
+ get() {
548
+ return this[GENERATOR].level;
549
+ },
550
+ set(level) {
551
+ this[GENERATOR].level = level;
552
+ }
493
553
  }
494
554
  }
495
- });
555
+ );
496
556
  var createStyler = (open, close, parent) => {
497
557
  let openAll;
498
558
  let closeAll;
@@ -512,15 +572,23 @@ var createStyler = (open, close, parent) => {
512
572
  };
513
573
  };
514
574
  var createBuilder = (self, _styler, _isEmpty) => {
515
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
575
+ const builder = (...arguments_) => {
576
+ if (arguments_.length === 1) {
577
+ return applyStyle(builder, "" + arguments_[0]);
578
+ }
579
+ if (arguments_.length === 2) {
580
+ return applyStyle(builder, arguments_[0] + " " + arguments_[1]);
581
+ }
582
+ return applyStyle(builder, arguments_.join(" "));
583
+ };
516
584
  Object.setPrototypeOf(builder, proto);
517
- builder[GENERATOR] = self;
585
+ builder[GENERATOR] = self[GENERATOR] ?? self;
518
586
  builder[STYLER] = _styler;
519
587
  builder[IS_EMPTY] = _isEmpty;
520
588
  return builder;
521
589
  };
522
590
  var applyStyle = (self, string) => {
523
- if (self.level <= 0 || !string) {
591
+ if (self[GENERATOR][LEVEL] <= 0 || !string) {
524
592
  return self[IS_EMPTY] ? "" : string;
525
593
  }
526
594
  let styler = self[STYLER];
@@ -540,7 +608,7 @@ var applyStyle = (self, string) => {
540
608
  }
541
609
  return openAll + string + closeAll;
542
610
  };
543
- Object.defineProperties(createChalk.prototype, styles2);
611
+ Object.defineProperties(createChalk.prototype, { ...styles2, level: levelDescriptor });
544
612
  var chalk = createChalk();
545
613
  var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
546
614
  var index_default = chalk;
@@ -557,5 +625,6 @@ var index_default = chalk;
557
625
  modifierNames,
558
626
  modifiers,
559
627
  supportsColor,
560
- supportsColorStderr
628
+ supportsColorStderr,
629
+ underlineColorNames
561
630
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjser/chalk",
3
- "version": "5.6.2-cjser.2",
3
+ "version": "6.0.0-cjser.2",
4
4
  "description": "Terminal string styling done right",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "funding": "https://github.com/chalk/chalk?sponsor=1",
11
11
  "type": "module",
12
- "main": "./dist-cjser/index.cjs",
13
12
  "exports": {
13
+ "types": "./source/index.d.ts",
14
14
  "require": "./dist-cjser/index.cjs",
15
15
  "default": "./source/index.js"
16
16
  },
@@ -21,18 +21,16 @@
21
21
  "default": "./source/vendor/supports-color/browser.js"
22
22
  }
23
23
  },
24
- "types": "./source/index.d.ts",
25
24
  "sideEffects": false,
26
25
  "engines": {
27
- "node": "^12.17.0 || ^14.13 || >=16.0.0"
26
+ "node": ">=22"
28
27
  },
29
28
  "scripts": {
30
- "test": "xo && c8 ava && tsd",
29
+ "test": "xo && c8 ava && tsc --noEmit --types node source/index.d.ts",
31
30
  "bench": "matcha benchmark.js"
32
31
  },
33
32
  "files": [
34
33
  "source",
35
- "!source/index.test-d.ts",
36
34
  "dist-cjser"
37
35
  ],
38
36
  "keywords": [
@@ -58,26 +56,35 @@
58
56
  "text"
59
57
  ],
60
58
  "devDependencies": {
61
- "@types/node": "^16.11.10",
62
- "ava": "^3.15.0",
63
- "c8": "^7.10.0",
64
- "color-convert": "^2.0.1",
65
- "execa": "^6.0.0",
66
- "log-update": "^5.0.0",
59
+ "@types/node": "^26.1.1",
60
+ "ansi-styles": "^6.2.3",
61
+ "ava": "^8.0.1",
62
+ "c8": "^12.0.0",
63
+ "color-convert": "^3.1.3",
64
+ "execa": "^10.0.0",
65
+ "log-update": "^8.0.0",
67
66
  "matcha": "^0.7.0",
68
- "tsd": "^0.19.0",
69
- "xo": "^0.57.0",
67
+ "typescript": "^6.0.3",
68
+ "xo": "^4.0.0",
70
69
  "yoctodelay": "^2.0.0"
71
70
  },
72
- "xo": {
73
- "rules": {
74
- "unicorn/prefer-string-slice": "off",
75
- "@typescript-eslint/consistent-type-imports": "off",
76
- "@typescript-eslint/consistent-type-exports": "off",
77
- "@typescript-eslint/consistent-type-definitions": "off",
78
- "unicorn/expiring-todo-comments": "off"
71
+ "xo": [
72
+ {
73
+ "ignores": [
74
+ "source/vendor"
75
+ ]
76
+ },
77
+ {
78
+ "rules": {
79
+ "unicorn/prefer-string-slice": "off",
80
+ "@typescript-eslint/consistent-type-imports": "off",
81
+ "@typescript-eslint/consistent-type-exports": "off",
82
+ "@typescript-eslint/consistent-type-definitions": "off",
83
+ "unicorn/expiring-todo-comments": "off",
84
+ "no-warning-comments": "off"
85
+ }
79
86
  }
80
- },
87
+ ],
81
88
  "c8": {
82
89
  "reporter": [
83
90
  "text",
@@ -87,21 +94,24 @@
87
94
  "source/vendor"
88
95
  ]
89
96
  },
97
+ "types": "./source/index.d.ts",
98
+ "main": "./dist-cjser/index.cjs",
90
99
  "cjser": {
91
- "sourceVersion": "5.6.2",
100
+ "sourceVersion": "6.0.0",
92
101
  "cjserVersion": 2,
93
102
  "original": {
94
103
  "name": "chalk",
95
- "version": "5.6.2",
96
- "main": "./source/index.js",
97
- "exports": "./source/index.js",
104
+ "version": "6.0.0",
105
+ "exports": {
106
+ "types": "./source/index.d.ts",
107
+ "default": "./source/index.js"
108
+ },
98
109
  "repository": "chalk/chalk",
99
110
  "files": [
100
- "source",
101
- "!source/index.test-d.ts"
111
+ "source"
102
112
  ],
103
113
  "scripts": {
104
- "test": "xo && c8 ava && tsd",
114
+ "test": "xo && c8 ava && tsc --noEmit --types node source/index.d.ts",
105
115
  "bench": "matcha benchmark.js"
106
116
  }
107
117
  }
package/readme.md CHANGED
@@ -140,21 +140,23 @@ const customChalk = new Chalk({level: 0});
140
140
  | `2` | 256 color support |
141
141
  | `3` | Truecolor support (16 million colors) |
142
142
 
143
+ Both the `level` option and the `level` property throw for anything that is not an integer from 0 to 3. Omit the option, or pass `undefined`, to have the level detected instead.
144
+
143
145
  ### supportsColor
144
146
 
145
147
  Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
146
148
 
147
- Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
149
+ Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. A numeric `FORCE_COLOR` overrides the detected color support and sets the level directly, meaning the terminal cannot raise it to a higher level. Use `FORCE_COLOR=true` to instead only enable color and let the level be detected.
148
150
 
149
- Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
151
+ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively. These take precedence over a non-zero numeric `FORCE_COLOR`.
150
152
 
151
153
  ### chalkStderr and supportsColorStderr
152
154
 
153
155
  `chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience.
154
156
 
155
- ### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames
157
+ ### modifierNames, foregroundColorNames, backgroundColorNames, underlineColorNames, and colorNames
156
158
 
157
- All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
159
+ All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`. Underline color names are kept separate in `underlineColorNames`.
158
160
 
159
161
  This can be useful if you wrap Chalk and need to validate input:
160
162
 
@@ -177,11 +179,15 @@ console.log(foregroundColorNames.includes('pink'));
177
179
  - `dim` - Make the text have lower opacity.
178
180
  - `italic` - Make the text italic. *(Not widely supported)*
179
181
  - `underline` - Put a horizontal line below the text. *(Not widely supported)*
182
+ - `underlineDouble` - Put a double horizontal line below the text. *(Not widely supported)*
183
+ - `underlineCurly` - Put a curly horizontal line below the text. *(Not widely supported)*
184
+ - `underlineDotted` - Put a dotted horizontal line below the text. *(Not widely supported)*
185
+ - `underlineDashed` - Put a dashed horizontal line below the text. *(Not widely supported)*
180
186
  - `overline` - Put a horizontal line above the text. *(Not widely supported)*
181
- - `inverse`- Invert background and foreground colors.
187
+ - `inverse` - Invert background and foreground colors.
182
188
  - `hidden` - Print the text but make it invisible.
183
189
  - `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
184
- - `visible`- Print the text only when Chalk has a color level above zero. Can be useful for things that are purely cosmetic.
190
+ - `visible` - Print the text only when Chalk has a color level above zero. Can be useful for things that are purely cosmetic.
185
191
 
186
192
  ### Colors
187
193
 
@@ -221,22 +227,50 @@ console.log(foregroundColorNames.includes('pink'));
221
227
  - `bgCyanBright`
222
228
  - `bgWhiteBright`
223
229
 
230
+ ### Underline colors
231
+
232
+ The underline color is set independently of the text color, so the color is only visible when an underline style is also applied. For example, `chalk.underlineRed.underlineCurly('typo')` renders a red squiggle below otherwise unstyled text. *(Not widely supported)*
233
+
234
+ Unlike text and background colors, there is no basic 16-color form for underline colors, so they always use the 256-color escape. At level 1 they are downsampled to the first 16 palette entries rather than to a basic color code.
235
+
236
+ - `underlineBlack`
237
+ - `underlineRed`
238
+ - `underlineGreen`
239
+ - `underlineYellow`
240
+ - `underlineBlue`
241
+ - `underlineMagenta`
242
+ - `underlineCyan`
243
+ - `underlineWhite`
244
+ - `underlineBlackBright` (alias: `underlineGray`, `underlineGrey`)
245
+ - `underlineRedBright`
246
+ - `underlineGreenBright`
247
+ - `underlineYellowBright`
248
+ - `underlineBlueBright`
249
+ - `underlineMagentaBright`
250
+ - `underlineCyanBright`
251
+ - `underlineWhiteBright`
252
+
224
253
  ## 256 and Truecolor color support
225
254
 
226
255
  Chalk supports 256 colors and [Truecolor](https://github.com/termstandard/colors) (16 million colors) on supported terminal apps.
227
256
 
228
- Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
257
+ Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 91 (ANSI escape for bright red). The same applies to `ansi256` values, so `chalk.ansi256(196)` also becomes 91 at level 1.
229
258
 
230
259
  Examples:
231
260
 
232
261
  - `chalk.hex('#DEADED').underline('Hello, world!')`
233
262
  - `chalk.rgb(15, 100, 204).inverse('Hello!')`
234
263
 
235
- Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `hex` for foreground colors and `bgHex` for background colors).
264
+ Background versions of these models are prefixed with `bg` and the first letter of the model capitalized (e.g. `hex` for foreground colors and `bgHex` for background colors).
236
265
 
237
266
  - `chalk.bgHex('#DEADED').underline('Hello, world!')`
238
267
  - `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
239
268
 
269
+ Underline versions are prefixed with `underline` in the same way (e.g. `hex` for foreground colors and `underlineHex` for underline colors). They only take effect when an underline style is also applied.
270
+
271
+ - `chalk.underlineHex('#DEADED').underlineCurly('Hello, world!')`
272
+ - `chalk.underlineRgb(15, 100, 204).underline('Hello!')`
273
+
240
274
  The following color models can be used:
241
275
 
242
276
  - [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`