@jsenv/humanize 1.5.2 → 1.7.0

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.
Files changed (90) hide show
  1. package/dist/browser/jsenv_humanize_browser.js +539 -482
  2. package/dist/browser/jsenv_humanize_browser.js.map +76 -0
  3. package/dist/node/jsenv_humanize_node.js +58 -7
  4. package/dist/node/jsenv_humanize_node.js.map +97 -0
  5. package/dist/node/jsenv_humanize_node_modules.js +23 -15
  6. package/dist/node/jsenv_humanize_node_modules.js.map +21 -0
  7. package/package.json +20 -17
  8. package/src/_tests/byte/file_size.test.js +0 -18
  9. package/src/_tests/byte/memory.test.js +0 -11
  10. package/src/_tests/content_frame/content_frame.test.js +0 -156
  11. package/src/_tests/content_frame/snapshots/10_line_and_column_are_zero.txt +0 -2
  12. package/src/_tests/content_frame/snapshots/11_line_is_last.txt +0 -3
  13. package/src/_tests/content_frame/snapshots/1_basic.txt +0 -4
  14. package/src/_tests/content_frame/snapshots/2_basic_2.txt +0 -6
  15. package/src/_tests/content_frame/snapshots/3_empty_last_line.txt +0 -7
  16. package/src/_tests/content_frame/snapshots/4_no_column.txt +0 -3
  17. package/src/_tests/content_frame/snapshots/5_line_1_and_2_digits.txt +0 -3
  18. package/src/_tests/content_frame/snapshots/6_line_too_long_column_undefined.txt +0 -3
  19. package/src/_tests/content_frame/snapshots/7_line_too_long_column_near_start.txt +0 -4
  20. package/src/_tests/content_frame/snapshots/8_line_too_long_column_near_middle.txt +0 -4
  21. package/src/_tests/content_frame/snapshots/9_line_too_long_column_near_end.txt +0 -4
  22. package/src/_tests/js_value/_inspect.test.html +0 -22
  23. package/src/_tests/js_value/array.test.js +0 -72
  24. package/src/_tests/js_value/biginit.test.js +0 -35
  25. package/src/_tests/js_value/boolean.test.js +0 -45
  26. package/src/_tests/js_value/date.test.js +0 -15
  27. package/src/_tests/js_value/error.test.js +0 -33
  28. package/src/_tests/js_value/function.test.js +0 -51
  29. package/src/_tests/js_value/instance.test.js +0 -12
  30. package/src/_tests/js_value/null.test.js +0 -6
  31. package/src/_tests/js_value/number.test.js +0 -182
  32. package/src/_tests/js_value/object.test.js +0 -173
  33. package/src/_tests/js_value/regexp.test.js +0 -15
  34. package/src/_tests/js_value/string.test.js +0 -106
  35. package/src/_tests/js_value/symbol.test.js +0 -20
  36. package/src/_tests/js_value/undefined.test.js +0 -6
  37. package/src/_tests/log/log_long.test_manual.mjs +0 -39
  38. package/src/_tests/log/log_modified.test_manual.mjs +0 -7
  39. package/src/_tests/log/logger.test.mjs +0 -90
  40. package/src/_tests/log/spinner.duration.test_manual.mjs +0 -25
  41. package/src/_tests/log/spinner.test.mjs +0 -33
  42. package/src/_tests/log/spinner.test_manual.mjs +0 -15
  43. package/src/_tests/percentage/percentage_distribution.test.mjs +0 -89
  44. package/src/_tests/time/decimals.test.js +0 -119
  45. package/src/_tests/time/duration.test.js +0 -20
  46. package/src/_tests/time/ellapsed.test.js +0 -10
  47. package/src/ansi/ansi_browser.js +0 -3
  48. package/src/ansi/ansi_node.js +0 -13
  49. package/src/ansi/ansi_runtime_agnostic.js +0 -107
  50. package/src/byte/byte.js +0 -44
  51. package/src/content_frame/content_frame.js +0 -157
  52. package/src/error/error_to_html.js +0 -22
  53. package/src/error/error_to_markdown.js +0 -14
  54. package/src/js_value/array.js +0 -58
  55. package/src/js_value/bigint.js +0 -3
  56. package/src/js_value/bigint_object.js +0 -5
  57. package/src/js_value/boolean.js +0 -1
  58. package/src/js_value/boolean_object.js +0 -12
  59. package/src/js_value/constructor.js +0 -10
  60. package/src/js_value/date.js +0 -8
  61. package/src/js_value/error.js +0 -34
  62. package/src/js_value/function.js +0 -20
  63. package/src/js_value/humanize.js +0 -142
  64. package/src/js_value/null.js +0 -1
  65. package/src/js_value/number.js +0 -101
  66. package/src/js_value/number_object.js +0 -9
  67. package/src/js_value/object.js +0 -78
  68. package/src/js_value/regexp.js +0 -1
  69. package/src/js_value/string.js +0 -141
  70. package/src/js_value/string_object.js +0 -10
  71. package/src/js_value/symbol.js +0 -24
  72. package/src/js_value/undefined.js +0 -1
  73. package/src/log/LOG_LEVELS.js +0 -9
  74. package/src/log/call_orderer.js +0 -39
  75. package/src/log/detailed_message.js +0 -29
  76. package/src/log/details.js +0 -26
  77. package/src/log/dynamic_log.js +0 -186
  78. package/src/log/logger.js +0 -85
  79. package/src/log/section.js +0 -50
  80. package/src/log/spinner.js +0 -72
  81. package/src/log/task_log.js +0 -49
  82. package/src/main_browser.js +0 -13
  83. package/src/main_node.js +0 -24
  84. package/src/percentage/distribute_percentages.js +0 -53
  85. package/src/time/time.js +0 -151
  86. package/src/unicode/unicode_browser.js +0 -7
  87. package/src/unicode/unicode_node.js +0 -8
  88. package/src/unicode/unicode_runtime_agnostic.js +0 -56
  89. package/src/utils/decimals.js +0 -95
  90. package/src/utils/indentation.js +0 -38
@@ -1,15 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
- import { humanize } from "@jsenv/humanize";
3
-
4
- {
5
- const actual = humanize(/ok/g);
6
- const expect = "/ok/g";
7
- assert({ actual, expect });
8
- }
9
-
10
- {
11
- // eslint-disable-next-line prefer-regex-literals
12
- const actual = humanize(new RegExp("foo", "g"));
13
- const expect = "/foo/g";
14
- assert({ actual, expect });
15
- }
@@ -1,106 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
- import { humanize } from "@jsenv/humanize";
3
-
4
- {
5
- const actual = humanize(String.fromCharCode(127));
6
- const expect = `"\\x7F"`;
7
- assert({ actual, expect });
8
- }
9
-
10
- {
11
- const actual = humanize("");
12
- const expect = `""`;
13
- assert({ actual, expect });
14
- }
15
-
16
- {
17
- const actual = humanize("dam");
18
- const expect = `"dam"`;
19
- assert({ actual, expect });
20
- }
21
-
22
- {
23
- const actual = humanize("don't");
24
- const expect = `"don't"`;
25
- assert({ actual, expect });
26
- }
27
-
28
- {
29
- const actual = humanize("don't", { quote: "'" });
30
- const expect = `'don\\\'t'`;
31
- assert({ actual, expect });
32
- }
33
-
34
- {
35
- const actual = humanize(`his name is "dam"`);
36
- const expect = `'his name is "dam"'`;
37
- assert({ actual, expect });
38
- }
39
-
40
- {
41
- const actual = humanize(`his name is "dam"`, { quote: "'" });
42
- const expect = `'his name is "dam"'`;
43
- assert({ actual, expect });
44
- }
45
-
46
- {
47
- const actual = humanize("a\nb");
48
- const expect = `"a\\nb"`;
49
- assert({ actual, expect });
50
- }
51
-
52
- {
53
- const actual = humanize("a\rb");
54
- const expect = `"a\\rb"`;
55
- assert({ actual, expect });
56
- }
57
-
58
- {
59
- const actual = humanize("a\u2028b");
60
- const expect = `"a\\u2028b"`;
61
- assert({ actual, expect });
62
- }
63
-
64
- {
65
- const actual = humanize("a\u2029b");
66
- const expect = `"a\\u2029b"`;
67
- assert({ actual, expect });
68
- }
69
-
70
- {
71
- // eslint-disable-next-line no-new-wrappers
72
- const actual = humanize(new String(""));
73
- const expect = `String("")`;
74
- assert({
75
- actual,
76
- expect,
77
- });
78
- }
79
-
80
- {
81
- // eslint-disable-next-line no-new-wrappers
82
- const actual = humanize(new String("dam"));
83
- const expect = `String("dam")`;
84
- assert({
85
- actual,
86
- expect,
87
- });
88
- }
89
-
90
- {
91
- const actual = humanize("dam", { quote: "'" });
92
- const expect = `'dam'`;
93
- assert({ actual, expect });
94
- }
95
-
96
- {
97
- const actual = humanize(`\`"'`);
98
- const expect = `"\`\\\"'"`;
99
- assert({ actual, expect });
100
- }
101
-
102
- {
103
- const actual = humanize(`""''`);
104
- const expect = `\`""''\``;
105
- assert({ actual, expect });
106
- }
@@ -1,20 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
- import { humanize } from "@jsenv/humanize";
3
-
4
- {
5
- const actual = humanize(Symbol());
6
- const expect = "Symbol()";
7
- assert({ actual, expect });
8
- }
9
-
10
- {
11
- const actual = humanize(Symbol("foo"));
12
- const expect = `Symbol("foo")`;
13
- assert({ actual, expect });
14
- }
15
-
16
- {
17
- const actual = humanize(Symbol(42));
18
- const expect = `Symbol("42")`;
19
- assert({ actual, expect });
20
- }
@@ -1,6 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
- import { humanize } from "@jsenv/humanize";
3
-
4
- const actual = humanize(undefined);
5
- const expect = "undefined";
6
- assert({ actual, expect });
@@ -1,39 +0,0 @@
1
- // must be verfied by human eyes
2
- // depending on terminal height
3
- // either the whole log can be rewritten (updated)
4
- // or it will be kept and second log appended at the bottom
5
-
6
- import { createDynamicLog } from "@jsenv/humanize";
7
-
8
- const log = createDynamicLog();
9
- log.update(`
10
- 1
11
- 2
12
- 3
13
- 4
14
- 5
15
- 6
16
- 7
17
- 8
18
- 9
19
- 10
20
- 11
21
- 12
22
- 13
23
- 14
24
- 15
25
- 16
26
- 17
27
- 18`);
28
- log.update(`
29
- a
30
- b
31
- c
32
- d
33
- e
34
- f
35
- g`);
36
- log.update(`
37
- alpha
38
- beta
39
- gamma`);
@@ -1,7 +0,0 @@
1
- import { createDynamicLog } from "@jsenv/humanize";
2
-
3
- const dynamicLog = createDynamicLog();
4
- dynamicLog.update("hello");
5
- console.log("hey");
6
- dynamicLog.update("world");
7
- dynamicLog.update("!");
@@ -1,90 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
- import { createLogger } from "@jsenv/humanize";
3
-
4
- try {
5
- createLogger({ logLevel: "foo" });
6
- throw new Error("should throw");
7
- } catch (actual) {
8
- const expect = new Error(`unexpected logLevel.
9
- --- logLevel ---
10
- foo
11
- --- allowed log levels ---
12
- off
13
- error
14
- warn
15
- info
16
- debug`);
17
- assert({ actual, expect });
18
- }
19
-
20
- {
21
- const logger = createLogger();
22
- const actual = logger.levels;
23
- const expect = {
24
- debug: false,
25
- info: true,
26
- warn: true,
27
- error: true,
28
- };
29
- assert({ actual, expect });
30
- }
31
-
32
- {
33
- const logger = createLogger({ logLevel: "off" });
34
- const actual = logger.levels;
35
- const expect = {
36
- debug: false,
37
- info: false,
38
- warn: false,
39
- error: false,
40
- };
41
- assert({ actual, expect });
42
- }
43
-
44
- {
45
- const logger = createLogger({ logLevel: "debug" });
46
- const actual = logger.levels;
47
- const expect = {
48
- debug: true,
49
- info: true,
50
- warn: true,
51
- error: true,
52
- };
53
- assert({ actual, expect });
54
- }
55
-
56
- {
57
- const logger = createLogger({ logLevel: "info" });
58
- const actual = logger.levels;
59
- const expect = {
60
- debug: false,
61
- info: true,
62
- warn: true,
63
- error: true,
64
- };
65
- assert({ actual, expect });
66
- }
67
-
68
- {
69
- const logger = createLogger({ logLevel: "warn" });
70
- const actual = logger.levels;
71
- const expect = {
72
- debug: false,
73
- info: false,
74
- warn: true,
75
- error: true,
76
- };
77
- assert({ actual, expect });
78
- }
79
-
80
- {
81
- const logger = createLogger({ logLevel: "error" });
82
- const actual = logger.levels;
83
- const expect = {
84
- debug: false,
85
- info: false,
86
- warn: false,
87
- error: true,
88
- };
89
- assert({ actual, expect });
90
- }
@@ -1,25 +0,0 @@
1
- import { createDynamicLog, startSpinner } from "@jsenv/humanize";
2
-
3
- const dynamicLog = createDynamicLog();
4
- const startMs = Date.now();
5
- let msDuration = 0;
6
- let text = "Doing something";
7
- const spinner = startSpinner({
8
- dynamicLog,
9
- render: () => text,
10
- effect: () => {
11
- const intervalId = setInterval(() => {
12
- msDuration = Date.now() - startMs;
13
- text = `Doing something ${msDuration} ms`;
14
- }, 100);
15
- return () => {
16
- clearInterval(intervalId);
17
- };
18
- },
19
- });
20
- await new Promise((resolve) => setTimeout(resolve, 2500));
21
-
22
- spinner.stop("Done");
23
- console.log(`Done in ${msDuration} ms`);
24
-
25
- await new Promise((resolve) => setTimeout(resolve, 500));
@@ -1,33 +0,0 @@
1
- // import { assert } from "@jsenv/assert"
2
-
3
- // import { startSpinner } from "@jsenv/humanize"
4
- // import { spyStreamOutput } from "@jsenv/humanize/src/internal/spy_stream_output.js"
5
-
6
- // let getOutput = spyStreamOutput(process.stdout)
7
- // startSpinner({
8
- // frames: ["a", "b"],
9
- // text: "loading",
10
- // fps: 1,
11
- // })
12
-
13
- // {
14
- // const actual = getOutput()
15
- // const expect = `a loading\n`
16
- // assert({ actual, expect })
17
- // }
18
- // getOutput = spyStreamOutput(process.stdout)
19
- // await new Promise((resolve) => setTimeout(resolve, 1500))
20
-
21
- // {
22
- // const actual = getOutput()
23
- // const expect = `b loading\n`
24
- // assert({ actual, expect })
25
- // }
26
- // getOutput = spyStreamOutput(process.stdout)
27
- // await new Promise((resolve) => setTimeout(resolve, 1500))
28
-
29
- // {
30
- // const actual = getOutput()
31
- // const expect = `a loading\n`
32
- // assert({ actual, expect })
33
- // }
@@ -1,15 +0,0 @@
1
- import { createDynamicLog, startSpinner } from "@jsenv/humanize";
2
-
3
- const dynamicLog = createDynamicLog();
4
- const spinner = startSpinner({
5
- dynamicLog,
6
- render: () => "Loading and I would say even more",
7
- stopOnWriteFromOutside: true,
8
- });
9
-
10
- await new Promise((resolve) => setTimeout(resolve, 2500));
11
-
12
- dynamicLog.update("Hey");
13
- spinner.stop();
14
-
15
- await new Promise((resolve) => setTimeout(resolve, 500));
@@ -1,89 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
-
3
- import { distributePercentages } from "@jsenv/humanize";
4
-
5
- const test = (namedNumbers, expect) => {
6
- const actual = distributePercentages(namedNumbers);
7
- assert({ actual, expect });
8
- };
9
-
10
- test(
11
- {
12
- css: 24,
13
- html: 707,
14
- js: 6367,
15
- json: 0,
16
- other: 9997,
17
- },
18
- {
19
- css: 0.1,
20
- html: 4.1,
21
- js: 37.2,
22
- json: 0,
23
- other: 58.6,
24
- },
25
- );
26
- test(
27
- {
28
- a: 1,
29
- b: 999,
30
- },
31
- {
32
- a: 0.1,
33
- b: 99.9,
34
- },
35
- );
36
- test(
37
- {
38
- a: 1,
39
- b: 9_999,
40
- },
41
- {
42
- a: 0.01,
43
- b: 99.99,
44
- },
45
- );
46
- test(
47
- {
48
- a: 1,
49
- b: 99_999,
50
- },
51
- {
52
- a: 0.001,
53
- b: 99.999,
54
- },
55
- );
56
- test(
57
- {
58
- a: 56_052,
59
- b: 222_878,
60
- },
61
- {
62
- a: 20,
63
- b: 80,
64
- },
65
- );
66
- test(
67
- {
68
- a: 10,
69
- b: 90,
70
- },
71
- {
72
- a: 10,
73
- b: 90,
74
- },
75
- );
76
- test(
77
- {
78
- a: 1,
79
- b: 10,
80
- c: 100,
81
- d: 889,
82
- },
83
- {
84
- a: 0.1,
85
- b: 1,
86
- c: 10,
87
- d: 88.9,
88
- },
89
- );
@@ -1,119 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
-
3
- import {
4
- setCeiledPrecision,
5
- setFlooredPrecision,
6
- setPrecision,
7
- setRoundedPrecision,
8
- } from "@jsenv/humanize/src/utils/decimals.js";
9
-
10
- /* numbers between -1 and 1 */
11
- // rounds last decimal
12
- {
13
- const actual = setRoundedPrecision(0.54);
14
- const expect = 0.5;
15
- assert({ actual, expect });
16
- }
17
- {
18
- const actual = setRoundedPrecision(0.55);
19
- const expect = 0.6;
20
- assert({ actual, expect });
21
- }
22
- // floor last decimal
23
- {
24
- const actual = setFlooredPrecision(0.54);
25
- const expect = 0.5;
26
- assert({ actual, expect });
27
- }
28
- {
29
- const actual = setFlooredPrecision(0.55);
30
- const expect = 0.5;
31
- assert({ actual, expect });
32
- }
33
- {
34
- const actual = setFlooredPrecision(0.501);
35
- const expect = 0.5;
36
- assert({ actual, expect });
37
- }
38
- // ceil last decimal
39
- {
40
- const actual = setCeiledPrecision(0.54);
41
- const expect = 0.6;
42
- assert({ actual, expect });
43
- }
44
- {
45
- const actual = setCeiledPrecision(0.54);
46
- const expect = 0.6;
47
- assert({ actual, expect });
48
- }
49
- {
50
- const actual = setCeiledPrecision(0.501);
51
- const expect = 0.6;
52
- assert({ actual, expect });
53
- }
54
- // truncate last decimal
55
- {
56
- const actual = setPrecision(0.501);
57
- const expect = 0.5;
58
- assert({ actual, expect });
59
- }
60
- {
61
- const actual = setPrecision(0.56);
62
- const expect = 0.5;
63
- assert({ actual, expect });
64
- }
65
- // rounded tests
66
- {
67
- const actual = setRoundedPrecision(0.0101);
68
- const expect = 0.01;
69
- assert({ actual, expect });
70
- }
71
- {
72
- const actual = setRoundedPrecision(0.012);
73
- const expect = 0.01;
74
- assert({ actual, expect });
75
- }
76
- {
77
- const actual = setRoundedPrecision(0.016);
78
- const expect = 0.02;
79
- assert({ actual, expect });
80
- }
81
- {
82
- const actual = setRoundedPrecision(0.016556, {
83
- decimals: 3,
84
- });
85
- const expect = 0.0166;
86
- assert({ actual, expect });
87
- }
88
- {
89
- const actual = setRoundedPrecision(0);
90
- const expect = 0;
91
- assert({ actual, expect });
92
- }
93
- {
94
- const actual = setRoundedPrecision(-0.0015);
95
- const expect = -0.002;
96
- assert({ actual, expect });
97
- }
98
-
99
- /* numbers above 1 */
100
- {
101
- const actual = setRoundedPrecision(37.04);
102
- const expect = 37;
103
- assert({ actual, expect });
104
- }
105
- {
106
- const actual = setRoundedPrecision(37.05);
107
- const expect = 37.1;
108
- assert({ actual, expect });
109
- }
110
- {
111
- const actual = setCeiledPrecision(37.01);
112
- const expect = 37.1;
113
- assert({ actual, expect });
114
- }
115
- {
116
- const actual = setFlooredPrecision(37.01);
117
- const expect = 37;
118
- assert({ actual, expect });
119
- }
@@ -1,20 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
-
3
- import { humanizeDuration } from "@jsenv/humanize";
4
-
5
- const test = (durationInMs, expect) => {
6
- const actual = humanizeDuration(durationInMs);
7
- assert({ actual, expect });
8
- };
9
-
10
- test(0.1, "0 second");
11
- test(1.02, "0.001 second");
12
- test(1.52, "0.002 second");
13
- test(52, "0.05 second");
14
- test(55, "0.06 second");
15
- test(99, "0.1 second");
16
- test(999, "1 second");
17
- test(1_421, "1.4 seconds");
18
- test(61_421, "1 minute and 1 second");
19
- test(3_601_200, "1 hour");
20
- test(7_651_200, "2 hours and 8 minutes");
@@ -1,10 +0,0 @@
1
- import { assert } from "@jsenv/assert";
2
-
3
- import { humanizeEllapsedTime } from "@jsenv/humanize";
4
-
5
- const test = (durationInMs, expect) => {
6
- const actual = humanizeEllapsedTime(durationInMs);
7
- assert({ actual, expect });
8
- };
9
-
10
- test(2200, "2 seconds");
@@ -1,3 +0,0 @@
1
- import { createAnsi } from "./ansi_runtime_agnostic.js";
2
-
3
- export const ANSI = createAnsi({ supported: true });
@@ -1,13 +0,0 @@
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
- process.env.FORCE_COLOR === "1" ||
9
- processSupportsBasicColor ||
10
- // GitHub workflow does support ANSI but "supports-color" returns false
11
- // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
12
- process.env.GITHUB_WORKFLOW,
13
- });