@jsenv/humanize 1.1.3 → 1.2.1

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.
@@ -22,14 +22,34 @@ const createAnsi = ({
22
22
  MAGENTA: "\x1b[35m",
23
23
  CYAN: "\x1b[36m",
24
24
  GREY: "\x1b[90m",
25
- color: (text, ANSI_COLOR) => {
26
- return ANSI.supported && ANSI_COLOR ? "".concat(ANSI_COLOR).concat(text).concat(RESET) : text;
25
+ color: (text, color) => {
26
+ if (!ANSI.supported) {
27
+ return text;
28
+ }
29
+ if (!color) {
30
+ return text;
31
+ }
32
+ if (text.trim() === "") {
33
+ // cannot set color of blank chars
34
+ return text;
35
+ }
36
+ return "".concat(color).concat(text).concat(RESET);
27
37
  },
28
38
  BOLD: "\x1b[1m",
29
39
  UNDERLINE: "\x1b[4m",
30
40
  STRIKE: "\x1b[9m",
31
- effect: (text, ANSI_EFFECT) => {
32
- return ANSI.supported && ANSI_EFFECT ? "".concat(ANSI_EFFECT).concat(text).concat(RESET) : text;
41
+ effect: (text, effect) => {
42
+ if (!ANSI.supported) {
43
+ return text;
44
+ }
45
+ if (!effect) {
46
+ return text;
47
+ }
48
+ // cannot add effect to empty string
49
+ if (text === "") {
50
+ return text;
51
+ }
52
+ return "".concat(effect).concat(text).concat(RESET);
33
53
  }
34
54
  };
35
55
  return ANSI;
@@ -68,6 +88,9 @@ const createUnicode = ({
68
88
  get CIRCLE_CROSS_RAW() {
69
89
  return UNICODE.supported ? "\u24E7" : "(\xD7)";
70
90
  },
91
+ get CIRCLE_DOTTED_RAW() {
92
+ return UNICODE.supported ? "\u25CC" : "*";
93
+ },
71
94
  get COMMAND() {
72
95
  return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
73
96
  },
@@ -213,19 +213,35 @@ const createAnsi = ({ supported }) => {
213
213
  MAGENTA: "\x1b[35m",
214
214
  CYAN: "\x1b[36m",
215
215
  GREY: "\x1b[90m",
216
- color: (text, ANSI_COLOR) => {
217
- return ANSI.supported && ANSI_COLOR
218
- ? `${ANSI_COLOR}${text}${RESET}`
219
- : text;
216
+ color: (text, color) => {
217
+ if (!ANSI.supported) {
218
+ return text;
219
+ }
220
+ if (!color) {
221
+ return text;
222
+ }
223
+ if (text.trim() === "") {
224
+ // cannot set color of blank chars
225
+ return text;
226
+ }
227
+ return `${color}${text}${RESET}`;
220
228
  },
221
229
 
222
230
  BOLD: "\x1b[1m",
223
231
  UNDERLINE: "\x1b[4m",
224
232
  STRIKE: "\x1b[9m",
225
- effect: (text, ANSI_EFFECT) => {
226
- return ANSI.supported && ANSI_EFFECT
227
- ? `${ANSI_EFFECT}${text}${RESET}`
228
- : text;
233
+ effect: (text, effect) => {
234
+ if (!ANSI.supported) {
235
+ return text;
236
+ }
237
+ if (!effect) {
238
+ return text;
239
+ }
240
+ // cannot add effect to empty string
241
+ if (text === "") {
242
+ return text;
243
+ }
244
+ return `${effect}${text}${RESET}`;
229
245
  },
230
246
  };
231
247
 
@@ -236,6 +252,7 @@ const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic;
236
252
 
237
253
  const ANSI = createAnsi({
238
254
  supported:
255
+ process.env.FORCE_COLOR === "1" ||
239
256
  processSupportsBasicColor ||
240
257
  // GitHub workflow does support ANSI but "supports-color" returns false
241
258
  // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
@@ -283,6 +300,9 @@ const createUnicode = ({ supported, ANSI }) => {
283
300
  get CIRCLE_CROSS_RAW() {
284
301
  return UNICODE.supported ? `ⓧ` : `(×)`;
285
302
  },
303
+ get CIRCLE_DOTTED_RAW() {
304
+ return UNICODE.supported ? `◌` : `*`;
305
+ },
286
306
  get COMMAND() {
287
307
  return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
288
308
  },
@@ -312,7 +332,7 @@ const createUnicode = ({ supported, ANSI }) => {
312
332
  };
313
333
 
314
334
  const UNICODE = createUnicode({
315
- supported: isUnicodeSupported() || process.env.FORCE_UNICODE === "1",
335
+ supported: process.env.FORCE_UNICODE === "1" || isUnicodeSupported(),
316
336
  ANSI,
317
337
  });
318
338
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/humanize",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "description": "Generate messages meant to read by humans",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,32 +1,30 @@
1
- -------------- execution start --------------
2
- 21 files matching "testPlan" in /Users/damien.maillard/dev/perso/jsenv-core/packages/independent/humanize/src
1
+ ------------ 23 executions ready ------------
2
+ directory: /Users/damien.maillard/dev/perso/jsenv-core/packages/independent/humanize/src
3
3
  ---------------------------------------------
4
-
5
- ✔ 01/23 _tests/byte/file_size.test.js [node/0.06s] (1 completed)
6
- ✔ 02/23 _tests/byte/memory.test.js [node/0.05s] (2 completed)
7
- ✔ 03/23 _tests/content_frame/content_frame.test.js [node/0.1s] (3 completed)
8
- ✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.4s] (4 completed)
4
+ ✔ 01/23 _tests/byte/file_size.test.js [node/0.04s] (1 completed)
5
+ ✔ 02/23 _tests/byte/memory.test.js [node/0.03s] (2 completed)
6
+ ✔ 03/23 _tests/content_frame/content_frame.test.js [node/0.09s] (3 completed)
7
+ ✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.2s] (4 completed)
9
8
  ✔ 05/23 _tests/js_value/_inspect.test.html [firefox/0.2s] (5 completed)
10
9
  ✔ 06/23 _tests/js_value/_inspect.test.html [webkit/0.4s] (6 completed)
11
- ✔ 07/23 _tests/js_value/array.test.js [node/0.06s] (7 completed)
12
- ✔ 08/23 _tests/js_value/biginit.test.js [node/0.07s] (8 completed)
10
+ ✔ 07/23 _tests/js_value/array.test.js [node/0.03s] (7 completed)
11
+ ✔ 08/23 _tests/js_value/biginit.test.js [node/0.04s] (8 completed)
13
12
  ✔ 09/23 _tests/js_value/boolean.test.js [node/0.05s] (9 completed)
14
- ✔ 10/23 _tests/js_value/date.test.js [node/0.03s] (10 completed)
15
- ✔ 11/23 _tests/js_value/error.test.js [node/0.04s] (11 completed)
13
+ ✔ 10/23 _tests/js_value/date.test.js [node/0.05s] (10 completed)
14
+ ✔ 11/23 _tests/js_value/error.test.js [node/0.05s] (11 completed)
16
15
  ✔ 12/23 _tests/js_value/function.test.js [node/0.04s] (12 completed)
17
- ✔ 13/23 _tests/js_value/instance.test.js [node/0.05s] (13 completed)
18
- ✔ 14/23 _tests/js_value/null.test.js [node/0.2s] (14 completed)
19
- ✔ 15/23 _tests/js_value/number.test.js [node/0.2s] (15 completed)
20
- ✔ 16/23 _tests/js_value/object.test.js [node/0.2s] (16 completed)
16
+ ✔ 13/23 _tests/js_value/instance.test.js [node/0.04s] (13 completed)
17
+ ✔ 14/23 _tests/js_value/null.test.js [node/0.05s] (14 completed)
18
+ ✔ 15/23 _tests/js_value/number.test.js [node/0.05s] (15 completed)
19
+ ✔ 16/23 _tests/js_value/object.test.js [node/0.05s] (16 completed)
21
20
  ✔ 17/23 _tests/js_value/regexp.test.js [node/0.05s] (17 completed)
22
- ✔ 18/23 _tests/js_value/string.test.js [node/0.04s] (18 completed)
23
- ✔ 19/23 _tests/js_value/symbol.test.js [node/0.04s] (19 completed)
24
- ✔ 20/23 _tests/js_value/undefined.test.js [node/0.03s] (20 completed)
25
- ✔ 21/23 _tests/time/decimals.test.js [node/0.03s] (21 completed)
26
- ✔ 22/23 _tests/time/duration.test.js [node/0.03s] (22 completed)
27
- ✔ 23/23 _tests/time/ellapsed.test.js [node/0.03s] (all completed)
28
-
29
- --------------- execution end ---------------
30
- 23 executions: all completed
31
- duration: 5.1s (setup: 0.4s, execution: 3.2s, teardown: 1.9s)
21
+ ✔ 18/23 _tests/js_value/string.test.js [node/0.05s] (18 completed)
22
+ ✔ 19/23 _tests/js_value/symbol.test.js [node/0.06s] (19 completed)
23
+ ✔ 20/23 _tests/js_value/undefined.test.js [node/0.04s] (20 completed)
24
+ ✔ 21/23 _tests/time/decimals.test.js [node/0.04s] (21 completed)
25
+ ✔ 22/23 _tests/time/duration.test.js [node/0.04s] (22 completed)
26
+ ✔ 23/23 _tests/time/ellapsed.test.js [node/0.04s] (all completed)
27
+ ------------ 23 executions done -------------
28
+ status: all completed
29
+ duration: 2.8s (setup: 0.4s, execution: 2.6s, teardown: 0.2s)
32
30
  ---------------------------------------------
@@ -8,6 +8,7 @@ import { humanize } from "@jsenv/humanize";
8
8
  }
9
9
 
10
10
  {
11
+ // eslint-disable-next-line prefer-regex-literals
11
12
  const actual = humanize(new RegExp("foo", "g"));
12
13
  const expect = "/foo/g";
13
14
  assert({ actual, expect });
@@ -5,6 +5,7 @@ const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic;
5
5
 
6
6
  export const ANSI = createAnsi({
7
7
  supported:
8
+ process.env.FORCE_COLOR === "1" ||
8
9
  processSupportsBasicColor ||
9
10
  // GitHub workflow does support ANSI but "supports-color" returns false
10
11
  // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
@@ -13,19 +13,35 @@ export const createAnsi = ({ supported }) => {
13
13
  MAGENTA: "\x1b[35m",
14
14
  CYAN: "\x1b[36m",
15
15
  GREY: "\x1b[90m",
16
- color: (text, ANSI_COLOR) => {
17
- return ANSI.supported && ANSI_COLOR
18
- ? `${ANSI_COLOR}${text}${RESET}`
19
- : text;
16
+ color: (text, color) => {
17
+ if (!ANSI.supported) {
18
+ return text;
19
+ }
20
+ if (!color) {
21
+ return text;
22
+ }
23
+ if (text.trim() === "") {
24
+ // cannot set color of blank chars
25
+ return text;
26
+ }
27
+ return `${color}${text}${RESET}`;
20
28
  },
21
29
 
22
30
  BOLD: "\x1b[1m",
23
31
  UNDERLINE: "\x1b[4m",
24
32
  STRIKE: "\x1b[9m",
25
- effect: (text, ANSI_EFFECT) => {
26
- return ANSI.supported && ANSI_EFFECT
27
- ? `${ANSI_EFFECT}${text}${RESET}`
28
- : text;
33
+ effect: (text, effect) => {
34
+ if (!ANSI.supported) {
35
+ return text;
36
+ }
37
+ if (!effect) {
38
+ return text;
39
+ }
40
+ // cannot add effect to empty string
41
+ if (text === "") {
42
+ return text;
43
+ }
44
+ return `${effect}${text}${RESET}`;
29
45
  },
30
46
  };
31
47
 
@@ -3,6 +3,6 @@ import { createUnicode } from "./unicode_runtime_agnostic.js";
3
3
  import { ANSI } from "../ansi/ansi_node.js";
4
4
 
5
5
  export const UNICODE = createUnicode({
6
- supported: isUnicodeSupported() || process.env.FORCE_UNICODE === "1",
6
+ supported: process.env.FORCE_UNICODE === "1" || isUnicodeSupported(),
7
7
  ANSI,
8
8
  });
@@ -24,6 +24,9 @@ export const createUnicode = ({ supported, ANSI }) => {
24
24
  get CIRCLE_CROSS_RAW() {
25
25
  return UNICODE.supported ? `ⓧ` : `(×)`;
26
26
  },
27
+ get CIRCLE_DOTTED_RAW() {
28
+ return UNICODE.supported ? `◌` : `*`;
29
+ },
27
30
  get COMMAND() {
28
31
  return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
29
32
  },