@jsenv/humanize 1.2.0 → 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;
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/humanize",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Generate messages meant to read by humans",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,30 +1,30 @@
1
1
  ------------ 23 executions ready ------------
2
2
  directory: /Users/damien.maillard/dev/perso/jsenv-core/packages/independent/humanize/src
3
3
  ---------------------------------------------
4
- ✔ 01/23 _tests/byte/file_size.test.js [node/0.03s] (1 completed)
4
+ ✔ 01/23 _tests/byte/file_size.test.js [node/0.04s] (1 completed)
5
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.07s] (3 completed)
7
- ✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.4s] (4 completed)
8
- ✔ 05/23 _tests/js_value/_inspect.test.html [firefox/0.1s] (5 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)
8
+ ✔ 05/23 _tests/js_value/_inspect.test.html [firefox/0.2s] (5 completed)
9
9
  ✔ 06/23 _tests/js_value/_inspect.test.html [webkit/0.4s] (6 completed)
10
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.03s] (8 completed)
12
- ✔ 09/23 _tests/js_value/boolean.test.js [node/0.06s] (9 completed)
11
+ ✔ 08/23 _tests/js_value/biginit.test.js [node/0.04s] (8 completed)
12
+ ✔ 09/23 _tests/js_value/boolean.test.js [node/0.05s] (9 completed)
13
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.07s] (11 completed)
14
+ ✔ 11/23 _tests/js_value/error.test.js [node/0.05s] (11 completed)
15
15
  ✔ 12/23 _tests/js_value/function.test.js [node/0.04s] (12 completed)
16
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.03s] (14 completed)
17
+ ✔ 14/23 _tests/js_value/null.test.js [node/0.05s] (14 completed)
18
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.06s] (16 completed)
20
- ✔ 17/23 _tests/js_value/regexp.test.js [node/0.04s] (17 completed)
21
- ✔ 18/23 _tests/js_value/string.test.js [node/0.03s] (18 completed)
22
- ✔ 19/23 _tests/js_value/symbol.test.js [node/0.04s] (19 completed)
19
+ ✔ 16/23 _tests/js_value/object.test.js [node/0.05s] (16 completed)
20
+ ✔ 17/23 _tests/js_value/regexp.test.js [node/0.05s] (17 completed)
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
23
  ✔ 20/23 _tests/js_value/undefined.test.js [node/0.04s] (20 completed)
24
- ✔ 21/23 _tests/time/decimals.test.js [node/0.05s] (21 completed)
25
- ✔ 22/23 _tests/time/duration.test.js [node/0.05s] (22 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
26
  ✔ 23/23 _tests/time/ellapsed.test.js [node/0.04s] (all completed)
27
27
  ------------ 23 executions done -------------
28
28
  status: all completed
29
- duration: 2.5s (setup: 0.4s, execution: 2.4s, teardown: 0.2s)
29
+ duration: 2.8s (setup: 0.4s, execution: 2.6s, teardown: 0.2s)
30
30
  ---------------------------------------------
@@ -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