@jsenv/humanize 1.1.0 → 1.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/humanize",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Generate messages meant to read by humans",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -7,26 +7,26 @@
7
7
  ✔ 03/23 _tests/content_frame/content_frame.test.js [node/0.07s] (3 completed)
8
8
  ✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.2s] (4 completed)
9
9
  ✔ 05/23 _tests/js_value/_inspect.test.html [firefox/0.1s] (5 completed)
10
- ✔ 06/23 _tests/js_value/_inspect.test.html [webkit/0.3s] (6 completed)
10
+ ✔ 06/23 _tests/js_value/_inspect.test.html [webkit/0.2s] (6 completed)
11
11
  ✔ 07/23 _tests/js_value/array.test.js [node/0.03s] (7 completed)
12
12
  ✔ 08/23 _tests/js_value/biginit.test.js [node/0.03s] (8 completed)
13
- ✔ 09/23 _tests/js_value/boolean.test.js [node/0.1s] (9 completed)
14
- ✔ 10/23 _tests/js_value/date.test.js [node/0.1s] (10 completed)
15
- ✔ 11/23 _tests/js_value/error.test.js [node/0.1s] (11 completed)
16
- ✔ 12/23 _tests/js_value/function.test.js [node/0.05s] (12 completed)
17
- ✔ 13/23 _tests/js_value/instance.test.js [node/0.1s] (13 completed)
18
- ✔ 14/23 _tests/js_value/null.test.js [node/0.04s] (14 completed)
13
+ ✔ 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.03s] (11 completed)
16
+ ✔ 12/23 _tests/js_value/function.test.js [node/0.04s] (12 completed)
17
+ ✔ 13/23 _tests/js_value/instance.test.js [node/0.03s] (13 completed)
18
+ ✔ 14/23 _tests/js_value/null.test.js [node/0.05s] (14 completed)
19
19
  ✔ 15/23 _tests/js_value/number.test.js [node/0.06s] (15 completed)
20
- ✔ 16/23 _tests/js_value/object.test.js [node/0.06s] (16 completed)
21
- ✔ 17/23 _tests/js_value/regexp.test.js [node/0.04s] (17 completed)
22
- ✔ 18/23 _tests/js_value/string.test.js [node/0.05s] (18 completed)
23
- ✔ 19/23 _tests/js_value/symbol.test.js [node/0.02s] (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)
20
+ ✔ 16/23 _tests/js_value/object.test.js [node/0.07s] (16 completed)
21
+ ✔ 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.03s] (19 completed)
24
+ ✔ 20/23 _tests/js_value/undefined.test.js [node/0.02s] (20 completed)
25
+ ✔ 21/23 _tests/time/decimals.test.js [node/0.02s] (21 completed)
26
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)
27
+ ✔ 23/23 _tests/time/ellapsed.test.js [node/0.02s] (all completed)
28
28
 
29
29
  --------------- execution end ---------------
30
30
  23 executions: all completed
31
- duration: 2.6s (setup: 0.4s, execution: 2.4s, teardown: 0.2s)
31
+ duration: 2.4s (setup: 0.4s, execution: 2.3s, teardown: 0.2s)
32
32
  ---------------------------------------------
@@ -0,0 +1,3 @@
1
+ import { createAnsi } from "./ansi_runtime_agnostic.js";
2
+
3
+ export const ANSI = createAnsi({ supported: true });
@@ -0,0 +1,16 @@
1
+ import { createSupportsColor } from "supports-color";
2
+ import { createAnsi } from "./ansi_runtime_agnostic.js";
3
+
4
+ const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic;
5
+
6
+ export const ANSI = createAnsi({
7
+ supported:
8
+ processSupportsBasicColor ||
9
+ // GitHub workflow does support ANSI but "supports-color" returns false
10
+ // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
11
+ (process.env.GITHUB_WORKFLOW &&
12
+ // Check on FORCE_COLOR is to ensure it is prio over GitHub workflow check
13
+ // in unit test we use process.env.FORCE_COLOR = 'false' to fake
14
+ // that colors are not supported. Let it have priority
15
+ process.env.FORCE_COLOR !== "false"),
16
+ });
@@ -0,0 +1,33 @@
1
+ // https://github.com/Marak/colors.js/blob/master/lib/styles.js
2
+ // https://stackoverflow.com/a/75985833/2634179
3
+ const RESET = "\x1b[0m";
4
+
5
+ export const createAnsi = ({ supported }) => {
6
+ const ANSI = {
7
+ supported,
8
+
9
+ RED: "\x1b[31m",
10
+ GREEN: "\x1b[32m",
11
+ YELLOW: "\x1b[33m",
12
+ BLUE: "\x1b[34m",
13
+ MAGENTA: "\x1b[35m",
14
+ CYAN: "\x1b[36m",
15
+ GREY: "\x1b[90m",
16
+ color: (text, ANSI_COLOR) => {
17
+ return ANSI.supported && ANSI_COLOR
18
+ ? `${ANSI_COLOR}${text}${RESET}`
19
+ : text;
20
+ },
21
+
22
+ BOLD: "\x1b[1m",
23
+ UNDERLINE: "\x1b[4m",
24
+ STRIKE: "\x1b[9m",
25
+ effect: (text, ANSI_EFFECT) => {
26
+ return ANSI.supported && ANSI_EFFECT
27
+ ? `${ANSI_EFFECT}${text}${RESET}`
28
+ : text;
29
+ },
30
+ };
31
+
32
+ return ANSI;
33
+ };
@@ -67,7 +67,7 @@ export const determineQuote = (
67
67
  return quoteDefault;
68
68
  };
69
69
 
70
- export const inspectChar = (char, { quote, preserveLineBreaks }) => {
70
+ const inspectChar = (char, { quote, preserveLineBreaks }) => {
71
71
  const point = char.charCodeAt(0);
72
72
  if (preserveLineBreaks && (char === "\n" || char === "\r")) {
73
73
  return char;
@@ -1,4 +1,4 @@
1
- import { ANSI } from "./ansi_node.js";
1
+ import { ANSI } from "../ansi/ansi_node.js";
2
2
 
3
3
  export const startSpinner = ({
4
4
  dynamicLog,
@@ -1,5 +1,5 @@
1
1
  import { humanizeDuration } from "../time/time.js";
2
- import { UNICODE } from "./unicode_node.js";
2
+ import { UNICODE } from "../unicode/unicode_node.js";
3
3
  import { createDynamicLog } from "./dynamic_log.js";
4
4
  import { startSpinner } from "./spinner.js";
5
5
 
@@ -1,13 +1,8 @@
1
1
  export { createDetailedMessage } from "./log/detailed_message.js";
2
-
2
+ export { ANSI } from "./ansi/ansi_browser.js";
3
+ export { UNICODE } from "./unicode/unicode_browser.js";
3
4
  export { humanize, humanizeMethodSymbol } from "./js_value/humanize.js";
4
- export { determineQuote, inspectChar } from "./js_value/string.js";
5
-
6
- export { ANSI } from "./log/ansi_browser.js";
7
- export { UNICODE } from "./log/unicode_browser.js";
8
-
9
5
  export { humanizeDuration, humanizeEllapsedTime } from "./time/time.js";
10
6
  export { humanizeFileSize, humanizeMemory } from "./byte/byte.js";
11
7
  export { distributePercentages } from "./percentage/distribute_percentages.js";
12
-
13
8
  export { generateContentFrame } from "./content_frame/content_frame.js";
package/src/main_node.js CHANGED
@@ -1,18 +1,14 @@
1
- // node only
2
- export { createLogger } from "./log/logger.js";
3
- export { createDynamicLog } from "./log/dynamic_log.js";
4
- export { startSpinner } from "./log/spinner.js";
5
- export { createTaskLog } from "./log/task_log.js";
6
1
  export { createDetailedMessage } from "./log/detailed_message.js";
7
-
8
- export { ANSI } from "./log/ansi_node.js";
9
- export { UNICODE } from "./log/unicode_node.js";
10
-
2
+ export { ANSI } from "./ansi/ansi_node.js";
3
+ export { UNICODE } from "./unicode/unicode_node.js";
11
4
  export { humanize, humanizeMethodSymbol } from "./js_value/humanize.js";
12
- export { determineQuote, inspectChar } from "./js_value/string.js";
13
-
14
5
  export { humanizeDuration, humanizeEllapsedTime } from "./time/time.js";
15
6
  export { humanizeFileSize, humanizeMemory } from "./byte/byte.js";
16
7
  export { distributePercentages } from "./percentage/distribute_percentages.js";
17
-
18
8
  export { generateContentFrame } from "./content_frame/content_frame.js";
9
+
10
+ // node only
11
+ export { createLogger } from "./log/logger.js";
12
+ export { createDynamicLog } from "./log/dynamic_log.js";
13
+ export { startSpinner } from "./log/spinner.js";
14
+ export { createTaskLog } from "./log/task_log.js";
@@ -0,0 +1,7 @@
1
+ import { createUnicode } from "./unicode_runtime_agnostic.js";
2
+ import { ANSI } from "../ansi/ansi_browser.js";
3
+
4
+ export const UNICODE = createUnicode({
5
+ supported: true,
6
+ ANSI,
7
+ });
@@ -0,0 +1,8 @@
1
+ import isUnicodeSupported from "is-unicode-supported";
2
+ import { createUnicode } from "./unicode_runtime_agnostic.js";
3
+ import { ANSI } from "../ansi/ansi_node.js";
4
+
5
+ export const UNICODE = createUnicode({
6
+ supported: isUnicodeSupported(),
7
+ ANSI,
8
+ });
@@ -0,0 +1,53 @@
1
+ // see also https://github.com/sindresorhus/figures
2
+
3
+ export const createUnicode = ({ supported, ANSI }) => {
4
+ const UNICODE = {
5
+ supported,
6
+ get COMMAND_RAW() {
7
+ return UNICODE.supported ? `❯` : `>`;
8
+ },
9
+ get OK_RAW() {
10
+ return UNICODE.supported ? `✔` : `√`;
11
+ },
12
+ get FAILURE_RAW() {
13
+ return UNICODE.supported ? `✖` : `×`;
14
+ },
15
+ get DEBUG_RAW() {
16
+ return UNICODE.supported ? `◆` : `♦`;
17
+ },
18
+ get INFO_RAW() {
19
+ return UNICODE.supported ? `ℹ` : `i`;
20
+ },
21
+ get WARNING_RAW() {
22
+ return UNICODE.supported ? `⚠` : `‼`;
23
+ },
24
+ get CIRCLE_CROSS_RAW() {
25
+ return UNICODE.supported ? `ⓧ` : `(×)`;
26
+ },
27
+ get COMMAND() {
28
+ return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
29
+ },
30
+ get OK() {
31
+ return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
32
+ },
33
+ get FAILURE() {
34
+ return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
35
+ },
36
+ get DEBUG() {
37
+ return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
38
+ },
39
+ get INFO() {
40
+ return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
41
+ },
42
+ get WARNING() {
43
+ return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
44
+ },
45
+ get CIRCLE_CROSS() {
46
+ return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
47
+ },
48
+ get ELLIPSIS() {
49
+ return UNICODE.supported ? `…` : `...`;
50
+ },
51
+ };
52
+ return UNICODE;
53
+ };
@@ -1,27 +0,0 @@
1
- // https://github.com/Marak/colors.js/blob/master/lib/styles.js
2
- // https://stackoverflow.com/a/75985833/2634179
3
- const RESET = "\x1b[0m";
4
-
5
- export const ANSI = {
6
- supported: true,
7
-
8
- RED: "\x1b[31m",
9
- GREEN: "\x1b[32m",
10
- YELLOW: "\x1b[33m",
11
- BLUE: "\x1b[34m",
12
- MAGENTA: "\x1b[35m",
13
- CYAN: "\x1b[36m",
14
- GREY: "\x1b[90m",
15
- color: (text, ANSI_COLOR) => {
16
- return ANSI.supported && ANSI_COLOR ? `${ANSI_COLOR}${text}${RESET}` : text;
17
- },
18
-
19
- BOLD: "\x1b[1m",
20
- UNDERLINE: "\x1b[4m",
21
- STRIKE: "\x1b[9m",
22
- effect: (text, ANSI_EFFECT) => {
23
- return ANSI.supported && ANSI_EFFECT
24
- ? `${ANSI_EFFECT}${text}${RESET}`
25
- : text;
26
- },
27
- };
@@ -1,42 +0,0 @@
1
- import { createSupportsColor } from "supports-color";
2
-
3
- const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic;
4
- // https://github.com/Marak/colors.js/blob/master/lib/styles.js
5
- // https://stackoverflow.com/a/75985833/2634179
6
- const RESET = "\x1b[0m";
7
-
8
- export const ANSI = {
9
- supported: processSupportsBasicColor,
10
-
11
- RED: "\x1b[31m",
12
- GREEN: "\x1b[32m",
13
- YELLOW: "\x1b[33m",
14
- BLUE: "\x1b[34m",
15
- MAGENTA: "\x1b[35m",
16
- CYAN: "\x1b[36m",
17
- GREY: "\x1b[90m",
18
- color: (text, ANSI_COLOR) => {
19
- return ANSI.supported && ANSI_COLOR ? `${ANSI_COLOR}${text}${RESET}` : text;
20
- },
21
-
22
- BOLD: "\x1b[1m",
23
- UNDERLINE: "\x1b[4m",
24
- STRIKE: "\x1b[9m",
25
- effect: (text, ANSI_EFFECT) => {
26
- return ANSI.supported && ANSI_EFFECT
27
- ? `${ANSI_EFFECT}${text}${RESET}`
28
- : text;
29
- },
30
- };
31
-
32
- // GitHub workflow does support ANSI but "supports-color" returns false
33
- // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
34
- if (
35
- process.env.GITHUB_WORKFLOW &&
36
- // Check on FORCE_COLOR is to ensure it is prio over GitHub workflow check
37
- // in unit test we use process.env.FORCE_COLOR = 'false' to fake
38
- // that colors are not supported. Let it have priority
39
- process.env.FORCE_COLOR !== "false"
40
- ) {
41
- ANSI.supported = true;
42
- }
@@ -1,53 +0,0 @@
1
- // see also https://github.com/sindresorhus/figures
2
-
3
- import { ANSI } from "./ansi_browser.js";
4
-
5
- export const UNICODE = {
6
- supported: true,
7
-
8
- get COMMAND_RAW() {
9
- return UNICODE.supported ? `❯` : `>`;
10
- },
11
- get OK_RAW() {
12
- return UNICODE.supported ? `✔` : `√`;
13
- },
14
- get FAILURE_RAW() {
15
- return UNICODE.supported ? `✖` : `×`;
16
- },
17
- get DEBUG_RAW() {
18
- return UNICODE.supported ? `◆` : `♦`;
19
- },
20
- get INFO_RAW() {
21
- return UNICODE.supported ? `ℹ` : `i`;
22
- },
23
- get WARNING_RAW() {
24
- return UNICODE.supported ? `⚠` : `‼`;
25
- },
26
- get CIRCLE_CROSS_RAW() {
27
- return UNICODE.supported ? `ⓧ` : `(×)`;
28
- },
29
- get COMMAND() {
30
- return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
31
- },
32
- get OK() {
33
- return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
34
- },
35
- get FAILURE() {
36
- return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
37
- },
38
- get DEBUG() {
39
- return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
40
- },
41
- get INFO() {
42
- return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
43
- },
44
- get WARNING() {
45
- return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
46
- },
47
- get CIRCLE_CROSS() {
48
- return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
49
- },
50
- get ELLIPSIS() {
51
- return UNICODE.supported ? `…` : `...`;
52
- },
53
- };
@@ -1,55 +0,0 @@
1
- // see also https://github.com/sindresorhus/figures
2
-
3
- import isUnicodeSupported from "is-unicode-supported";
4
-
5
- import { ANSI } from "./ansi_node.js";
6
-
7
- export const UNICODE = {
8
- supported: isUnicodeSupported(),
9
-
10
- get COMMAND_RAW() {
11
- return UNICODE.supported ? `❯` : `>`;
12
- },
13
- get OK_RAW() {
14
- return UNICODE.supported ? `✔` : `√`;
15
- },
16
- get FAILURE_RAW() {
17
- return UNICODE.supported ? `✖` : `×`;
18
- },
19
- get DEBUG_RAW() {
20
- return UNICODE.supported ? `◆` : `♦`;
21
- },
22
- get INFO_RAW() {
23
- return UNICODE.supported ? `ℹ` : `i`;
24
- },
25
- get WARNING_RAW() {
26
- return UNICODE.supported ? `⚠` : `‼`;
27
- },
28
- get CIRCLE_CROSS_RAW() {
29
- return UNICODE.supported ? `ⓧ` : `(×)`;
30
- },
31
- get COMMAND() {
32
- return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
33
- },
34
- get OK() {
35
- return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
36
- },
37
- get FAILURE() {
38
- return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
39
- },
40
- get DEBUG() {
41
- return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
42
- },
43
- get INFO() {
44
- return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
45
- },
46
- get WARNING() {
47
- return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
48
- },
49
- get CIRCLE_CROSS() {
50
- return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
51
- },
52
- get ELLIPSIS() {
53
- return UNICODE.supported ? `…` : `...`;
54
- },
55
- };