@jsenv/humanize 1.0.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 (79) hide show
  1. package/README.md +35 -0
  2. package/dist/browser/jsenv_humanize_browser.js +1157 -0
  3. package/dist/node/jsenv_humanize_node.js +2003 -0
  4. package/package.json +49 -0
  5. package/src/.jsenv/jsenv_tests_output.txt +35 -0
  6. package/src/_tests/byte/file_size.test.js +18 -0
  7. package/src/_tests/byte/memory_usage.test.js +11 -0
  8. package/src/_tests/content_frame/content_frame.test.js +156 -0
  9. package/src/_tests/content_frame/snapshots/10_line_and_column_are_zero.txt +2 -0
  10. package/src/_tests/content_frame/snapshots/11_line_is_last.txt +3 -0
  11. package/src/_tests/content_frame/snapshots/1_basic.txt +4 -0
  12. package/src/_tests/content_frame/snapshots/2_basic_2.txt +6 -0
  13. package/src/_tests/content_frame/snapshots/3_empty_last_line.txt +7 -0
  14. package/src/_tests/content_frame/snapshots/4_no_column.txt +3 -0
  15. package/src/_tests/content_frame/snapshots/5_line_1_and_2_digits.txt +3 -0
  16. package/src/_tests/content_frame/snapshots/6_line_too_long_column_undefined.txt +3 -0
  17. package/src/_tests/content_frame/snapshots/7_line_too_long_column_near_start.txt +4 -0
  18. package/src/_tests/content_frame/snapshots/8_line_too_long_column_near_middle.txt +4 -0
  19. package/src/_tests/content_frame/snapshots/9_line_too_long_column_near_end.txt +4 -0
  20. package/src/_tests/js_value/_inspect.test.html +22 -0
  21. package/src/_tests/js_value/array.test.js +72 -0
  22. package/src/_tests/js_value/biginit.test.js +36 -0
  23. package/src/_tests/js_value/boolean.test.js +45 -0
  24. package/src/_tests/js_value/date.test.js +15 -0
  25. package/src/_tests/js_value/error.test.js +33 -0
  26. package/src/_tests/js_value/function.test.js +51 -0
  27. package/src/_tests/js_value/instance.test.js +12 -0
  28. package/src/_tests/js_value/null.test.js +6 -0
  29. package/src/_tests/js_value/number.test.js +182 -0
  30. package/src/_tests/js_value/object.test.js +173 -0
  31. package/src/_tests/js_value/regexp.test.js +14 -0
  32. package/src/_tests/js_value/string.test.js +106 -0
  33. package/src/_tests/js_value/symbol.test.js +20 -0
  34. package/src/_tests/js_value/undefined.test.js +6 -0
  35. package/src/_tests/log/log_long.test.mjs +39 -0
  36. package/src/_tests/log/log_modified.test.mjs +7 -0
  37. package/src/_tests/log/logger.test.mjs +91 -0
  38. package/src/_tests/log/spinner.duration.test_manual.mjs +25 -0
  39. package/src/_tests/log/spinner.test.mjs +33 -0
  40. package/src/_tests/log/spinner.test_manual.mjs +15 -0
  41. package/src/_tests/percentage/percentage_distribution.test.mjs +89 -0
  42. package/src/_tests/time/decimals.test.js +119 -0
  43. package/src/_tests/time/duration.test.js +20 -0
  44. package/src/_tests/time/ellapsed.test.js +10 -0
  45. package/src/byte/byte.js +44 -0
  46. package/src/content_frame/content_frame.js +157 -0
  47. package/src/js_value/array.js +58 -0
  48. package/src/js_value/bigint.js +3 -0
  49. package/src/js_value/bigint_object.js +5 -0
  50. package/src/js_value/boolean.js +1 -0
  51. package/src/js_value/boolean_object.js +12 -0
  52. package/src/js_value/constructor.js +10 -0
  53. package/src/js_value/date.js +8 -0
  54. package/src/js_value/error.js +34 -0
  55. package/src/js_value/function.js +20 -0
  56. package/src/js_value/humanize.js +140 -0
  57. package/src/js_value/null.js +1 -0
  58. package/src/js_value/number.js +101 -0
  59. package/src/js_value/number_object.js +9 -0
  60. package/src/js_value/object.js +78 -0
  61. package/src/js_value/regexp.js +1 -0
  62. package/src/js_value/string.js +141 -0
  63. package/src/js_value/string_object.js +10 -0
  64. package/src/js_value/symbol.js +24 -0
  65. package/src/js_value/undefined.js +1 -0
  66. package/src/log/LOG_LEVELS.js +9 -0
  67. package/src/log/ansi.js +37 -0
  68. package/src/log/detailed_message.js +17 -0
  69. package/src/log/dynamic_log.js +185 -0
  70. package/src/log/logger.js +85 -0
  71. package/src/log/spinner.js +72 -0
  72. package/src/log/task_log.js +46 -0
  73. package/src/log/unicode.js +52 -0
  74. package/src/main_browser.js +10 -0
  75. package/src/main_node.js +18 -0
  76. package/src/percentage/distribute_percentages.js +53 -0
  77. package/src/time/time.js +151 -0
  78. package/src/utils/decimals.js +95 -0
  79. package/src/utils/indentation.js +38 -0
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@jsenv/humanize",
3
+ "version": "1.0.0",
4
+ "description": "Generate messages meant to read by humans",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/jsenv/core",
9
+ "directory": "packages/independent/humanize"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "engines": {
15
+ "node": ">=16.8.0"
16
+ },
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "browser": {
21
+ "development": "./src/main_browser.js",
22
+ "default": "./dist/browser/jsenv_humanize_browser.js"
23
+ },
24
+ "node": {
25
+ "development": "./src/main_node.js",
26
+ "default": "./dist/node/jsenv_humanize_node.js"
27
+ }
28
+ },
29
+ "./*": "./*"
30
+ },
31
+ "files": [
32
+ "/dist/",
33
+ "/src/"
34
+ ],
35
+ "scripts": {
36
+ "dev": "node ./scripts/dev.mjs",
37
+ "build": "node ./scripts/build.mjs",
38
+ "test": "node ./scripts/test.mjs",
39
+ "prepublishOnly": "npm run build"
40
+ },
41
+ "dependencies": {
42
+ "string-width": "7.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "ansi-escapes": "6.2.0",
46
+ "is-unicode-supported": "2.0.0",
47
+ "supports-color": "9.4.0"
48
+ }
49
+ }
@@ -0,0 +1,35 @@
1
+ ----------- 23 executions to run ------------
2
+ 20 with node (node_worker_thread@20.11.0)
3
+ 1 with chromium (chromium@120.0.6099.28)
4
+ 1 with firefox (firefox@119.0)
5
+ 1 with webkit (webkit@17.4)
6
+ ---------------------------------------------
7
+
8
+ ✔ 01/23 _tests/byte/file_size.test.js [node/0.03s/1.2MB] (1 completed)
9
+ ✔ 02/23 _tests/byte/memory_usage.test.js [node/0.03s/1.2MB] (2 completed)
10
+ ✔ 03/23 _tests/content_frame/content_frame.test.js [node/0.1s/2.6MB] (3 completed)
11
+ ✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.2s/10.1MB] (4 completed)
12
+ ✔ 05/23 _tests/js_value/_inspect.test.html [firefox/0.2s] (5 completed)
13
+ ✔ 06/23 _tests/js_value/_inspect.test.html [webkit/0.3s] (6 completed)
14
+ ✔ 07/23 _tests/js_value/array.test.js [node/0.09s/1.2MB] (7 completed)
15
+ ✔ 08/23 _tests/js_value/biginit.test.js [node/0.06s/1.2MB] (8 completed)
16
+ ✔ 09/23 _tests/js_value/boolean.test.js [node/0.1s/1.2MB] (9 completed)
17
+ ✔ 10/23 _tests/js_value/date.test.js [node/0.04s/1.2MB] (10 completed)
18
+ ✔ 11/23 _tests/js_value/error.test.js [node/0.05s/1.2MB] (11 completed)
19
+ ✔ 12/23 _tests/js_value/function.test.js [node/0.05s/1.2MB] (12 completed)
20
+ ✔ 13/23 _tests/js_value/instance.test.js [node/0.05s/1.2MB] (13 completed)
21
+ ✔ 14/23 _tests/js_value/null.test.js [node/0.04s/1.2MB] (14 completed)
22
+ ✔ 15/23 _tests/js_value/number.test.js [node/0.06s/1.3MB] (15 completed)
23
+ ✔ 16/23 _tests/js_value/object.test.js [node/0.05s/1.3MB] (16 completed)
24
+ ✔ 17/23 _tests/js_value/regexp.test.js [node/0.05s/1.2MB] (17 completed)
25
+ ✔ 18/23 _tests/js_value/string.test.js [node/0.05s/1.2MB] (18 completed)
26
+ ✔ 19/23 _tests/js_value/symbol.test.js [node/0.05s/1.2MB] (19 completed)
27
+ ✔ 20/23 _tests/js_value/undefined.test.js [node/0.06s/1.2MB] (20 completed)
28
+ ✔ 21/23 _tests/time/decimals.test.js [node/0.03s/1.2MB] (21 completed)
29
+ ✔ 22/23 _tests/time/duration.test.js [node/0.03s/1.2MB] (22 completed)
30
+ ✔ 23/23 _tests/time/ellapsed.test.js [node/0.02s/1.2MB] (all completed)
31
+
32
+ ------------------ summary ------------------
33
+ 23 executions: all completed
34
+ duration: 4.4s (setup: 0.4s, execution: 4.2s, teardown: 0.2s)
35
+ ---------------------------------------------
@@ -0,0 +1,18 @@
1
+ import { assert } from "@jsenv/assert";
2
+
3
+ import { humanizeFileSize } from "@jsenv/humanize";
4
+
5
+ const test = (fileSize, expected) => {
6
+ const actual = humanizeFileSize(fileSize);
7
+ assert({ actual, expected });
8
+ };
9
+
10
+ test(0, "0 B");
11
+ test(1, "1 B");
12
+ test(1000, "1 kB");
13
+ test(1110, "1.1 kB");
14
+ test(1010, "1 kB");
15
+ test(10100, "10.1 kB");
16
+ test(100100, "100 kB");
17
+ test(1000100, "1 MB");
18
+ test(1100000, "1.1 MB");
@@ -0,0 +1,11 @@
1
+ import { assert } from "@jsenv/assert";
2
+
3
+ import { humanizeMemoryUsage } from "@jsenv/humanize";
4
+
5
+ const test = (memoryUsageInBytes, expected) => {
6
+ const actual = humanizeMemoryUsage(memoryUsageInBytes);
7
+ assert({ actual, expected });
8
+ };
9
+
10
+ test(1000, "1.0 kB");
11
+ test(1100, "1.1 kB");
@@ -0,0 +1,156 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { takeFileSnapshot } from "@jsenv/snapshot";
3
+
4
+ import { generateContentFrame } from "@jsenv/humanize";
5
+
6
+ let number = 1;
7
+ const test = (name, params) => {
8
+ const snapshotFileUrl = new URL(
9
+ `./snapshots/${number}_${name}`,
10
+ import.meta.url,
11
+ );
12
+ number++;
13
+ const fileSnapshot = takeFileSnapshot(snapshotFileUrl);
14
+ const inspectContentResult = generateContentFrame(params);
15
+ writeFileSync(snapshotFileUrl, inspectContentResult);
16
+ fileSnapshot.compare();
17
+ return inspectContentResult;
18
+ };
19
+
20
+ test("basic.txt", {
21
+ content: `const a = false;
22
+ const b = true;
23
+ const c = true;
24
+ const d = true;
25
+ const e = false;
26
+ `,
27
+ line: 3,
28
+ column: 1,
29
+ linesAbove: 1,
30
+ linesBelow: 1,
31
+ });
32
+
33
+ test("basic_2.txt", {
34
+ content: `const a = false;
35
+ const b = true;
36
+ const c = true;
37
+ const d = true;
38
+ const e = false;`,
39
+ line: 3,
40
+ column: 7,
41
+ linesAbove: 4,
42
+ linesBelow: 2,
43
+ });
44
+
45
+ test("empty_last_line.txt", {
46
+ content: `const a = false;
47
+ const b = true;
48
+ const c = true;
49
+ const d = true;
50
+ const e = false;
51
+ `,
52
+ line: 3,
53
+ column: 1,
54
+ linesAbove: 4,
55
+ linesBelow: 3,
56
+ });
57
+
58
+ test("no_column.txt", {
59
+ content: `const a = false;
60
+ const b = true;
61
+ const c = true;
62
+ const d = true;
63
+ const e = false;
64
+ `,
65
+ line: 3,
66
+ linesAbove: 1,
67
+ linesBelow: 1,
68
+ });
69
+
70
+ test("line_1_and_2_digits.txt", {
71
+ content: `const a = false;
72
+ const b = false;
73
+ const c = false;
74
+ const d = false;
75
+ const e = false;
76
+ const f = false;
77
+ const g = false;
78
+ const h = false;
79
+ const i = true;
80
+ const j = true;
81
+ const k = true;
82
+ const l = true;`,
83
+ line: 10,
84
+ linesAbove: 1,
85
+ linesBelow: 1,
86
+ });
87
+
88
+ test("line_too_long_column_undefined.txt", {
89
+ content: `const a = false;
90
+ const b = true;
91
+ const thisVariableNameisQuiteLong = true;
92
+ const d = true;
93
+ const e = false;
94
+ `,
95
+ line: 3,
96
+ linesAbove: 1,
97
+ linesBelow: 1,
98
+ lineMaxWidth: 15,
99
+ });
100
+
101
+ test("line_too_long_column_near_start.txt", {
102
+ content: `const a = false;
103
+ const b = true;
104
+ const thisVariableNameisQuiteLong = true;
105
+ const d = true;
106
+ const e = false;
107
+ `,
108
+ line: 3,
109
+ column: 4,
110
+ linesAbove: 1,
111
+ linesBelow: 1,
112
+ lineMaxWidth: 15,
113
+ });
114
+
115
+ test("line_too_long_column_near_middle.txt", {
116
+ content: `const a = false;
117
+ const b = true
118
+ const thisVariableNameisQuiteLong = true;
119
+ const d = tru
120
+ const e = false;
121
+ `,
122
+ line: 3,
123
+ column: 20,
124
+ linesAbove: 1,
125
+ linesBelow: 1,
126
+ lineMaxWidth: 14,
127
+ });
128
+
129
+ test("line_too_long_column_near_end.txt", {
130
+ content: `const a = false;
131
+
132
+ const thisVariableNameisQuiteLong = true;
133
+ const d = tru
134
+ const e = false;
135
+ `,
136
+ line: 3,
137
+ column: 35,
138
+ linesAbove: 1,
139
+ linesBelow: 1,
140
+ lineMaxWidth: 15,
141
+ });
142
+
143
+ test("line_and_column_are_zero.txt", {
144
+ content: `const a = false;`,
145
+ line: 0,
146
+ column: 0,
147
+ });
148
+
149
+ test("line_is_last.txt", {
150
+ content: `const a = false;
151
+ const b = false;
152
+ const c = true;`,
153
+ line: 2,
154
+ linesBelow: 0,
155
+ column: 0,
156
+ });
@@ -0,0 +1,2 @@
1
+ 1 | const a = false;
2
+ ^
@@ -0,0 +1,3 @@
1
+ 1 | const a = false;
2
+ 2 | const b = false;
3
+ ^
@@ -0,0 +1,4 @@
1
+ 2 | const b = true;
2
+ 3 | const c = true;
3
+ ^
4
+ 4 | const d = true;
@@ -0,0 +1,6 @@
1
+ 1 | const a = false;
2
+ 2 | const b = true;
3
+ 3 | const c = true;
4
+ ^
5
+ 4 | const d = true;
6
+ 5 | const e = false;
@@ -0,0 +1,7 @@
1
+ 1 | const a = false;
2
+ 2 | const b = true;
3
+ 3 | const c = true;
4
+ ^
5
+ 4 | const d = true;
6
+ 5 | const e = false;
7
+ 6 |
@@ -0,0 +1,3 @@
1
+ 2 | const b = true;
2
+ > 3 | const c = true;
3
+ 4 | const d = true;
@@ -0,0 +1,3 @@
1
+ 9 | const i = true;
2
+ > 10 | const j = true;
3
+ 11 | const k = true;
@@ -0,0 +1,3 @@
1
+ 2 | const b = true;
2
+ > 3 | const thisVari…
3
+ 4 | const d = true;
@@ -0,0 +1,4 @@
1
+ 2 | const b = true;
2
+ 3 | const thisVari…
3
+ ^
4
+ 4 | const d = true;
@@ -0,0 +1,4 @@
1
+ 2 |
2
+ 3 | …ableNameisQu…
3
+ ^
4
+ 4 |
@@ -0,0 +1,4 @@
1
+ 2 |
2
+ 3 | …eLong = true;
3
+ ^
4
+ 4 |
@@ -0,0 +1,22 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Inspect tests</title>
5
+ <meta charset="utf-8" />
6
+ <link rel="icon" href="data:," />
7
+ </head>
8
+
9
+ <body>
10
+ <script type="module" src="./array.test.js"></script>
11
+ <script type="module" src="./boolean.test.js"></script>
12
+ <script type="module" src="./date.test.js"></script>
13
+ <script type="module" src="./error.test.js"></script>
14
+ <script type="module" src="./function.test.js"></script>
15
+ <script type="module" src="./instance.test.js"></script>
16
+ <script type="module" src="./null.test.js"></script>
17
+ <script type="module" src="./number.test.js"></script>
18
+ <script type="module" src="./regexp.test.js"></script>
19
+ <script type="module" src="./symbol.test.js"></script>
20
+ <script type="module" src="./undefined.test.js"></script>
21
+ </body>
22
+ </html>
@@ -0,0 +1,72 @@
1
+ import { assert } from "@jsenv/assert";
2
+ import { humanize } from "@jsenv/humanize";
3
+
4
+ {
5
+ const actual = humanize([]);
6
+ const expected = `[]`;
7
+ assert({ actual, expected });
8
+ }
9
+
10
+ {
11
+ const actual = humanize([[]]);
12
+ const expected = `[
13
+ []
14
+ ]`;
15
+ assert({ actual, expected });
16
+ }
17
+
18
+ {
19
+ const actual = humanize(Array(3));
20
+ // prettier-ignore
21
+ const expected = `[
22
+ ,
23
+ ,
24
+ ${" "}
25
+ ]`
26
+ assert({ actual, expected });
27
+ }
28
+
29
+ {
30
+ const actual = humanize([Symbol()]);
31
+ const expected = `[
32
+ Symbol()
33
+ ]`;
34
+ assert({ actual, expected });
35
+ }
36
+
37
+ {
38
+ // eslint-disable-next-line no-array-constructor
39
+ const newArray = new Array("foo", 1);
40
+
41
+ {
42
+ const actual = humanize(newArray);
43
+ const expected = `[
44
+ "foo",
45
+ 1
46
+ ]`;
47
+ assert({
48
+ actual,
49
+ expected,
50
+ });
51
+ }
52
+
53
+ {
54
+ const actual = humanize(newArray);
55
+ const expected = `[
56
+ "foo",
57
+ 1
58
+ ]`;
59
+ assert({ actual, expected });
60
+ }
61
+ }
62
+
63
+ {
64
+ const circularArray = [0];
65
+ circularArray.push(circularArray);
66
+ const actual = humanize(circularArray);
67
+ const expected = `[
68
+ 0,
69
+ Symbol.for('circular')
70
+ ]`;
71
+ assert({ actual, expected });
72
+ }
@@ -0,0 +1,36 @@
1
+ /* eslint-disable no-eval */
2
+ import { assert } from "@jsenv/assert";
3
+ import { humanize } from "@jsenv/humanize";
4
+
5
+ {
6
+ const value = BigInt(1);
7
+ const actual = humanize(value);
8
+ const expected = "1n";
9
+ assert({ actual, expected });
10
+ }
11
+
12
+ {
13
+ const value = 2n;
14
+ const actual = humanize(value);
15
+ const expected = "2n";
16
+ assert({ actual, expected });
17
+ }
18
+
19
+ {
20
+ const value = Object(BigInt(1));
21
+ const actual = humanize(value);
22
+ const expected = "BigInt(1n)";
23
+ assert({ actual, expected });
24
+ }
25
+
26
+ {
27
+ const actual = humanize(1234567n);
28
+ const expected = "1234567n";
29
+ assert({ actual, expected });
30
+ }
31
+
32
+ {
33
+ const actual = humanize(19223n);
34
+ const expected = "19223n";
35
+ assert({ actual, expected });
36
+ }
@@ -0,0 +1,45 @@
1
+ import { assert } from "@jsenv/assert";
2
+ import { humanize } from "@jsenv/humanize";
3
+
4
+ {
5
+ const actual = humanize(true);
6
+ const expected = "true";
7
+ assert({ actual, expected });
8
+ }
9
+
10
+ {
11
+ const actual = humanize(false);
12
+ const expected = "false";
13
+ assert({ actual, expected });
14
+ }
15
+
16
+ /* eslint-disable no-new-wrappers */
17
+ {
18
+ const actual = humanize(new Boolean(true));
19
+ const expected = "Boolean(true)";
20
+ assert({ actual, expected });
21
+ }
22
+
23
+ {
24
+ const actual = humanize(new Boolean(true), { parenthesis: true });
25
+ const expected = "(Boolean(true))";
26
+ assert({ actual, expected });
27
+ }
28
+
29
+ {
30
+ const actual = humanize(new Boolean(true), { useNew: true });
31
+ const expected = "new Boolean(true)";
32
+ assert({ actual, expected });
33
+ }
34
+
35
+ {
36
+ const actual = humanize(new Boolean(true), {
37
+ parenthesis: true,
38
+ useNew: true,
39
+ });
40
+ const expected = "new (Boolean(true))";
41
+ assert({
42
+ actual,
43
+ expected,
44
+ });
45
+ }
@@ -0,0 +1,15 @@
1
+ import { assert } from "@jsenv/assert";
2
+ import { humanize } from "@jsenv/humanize";
3
+
4
+ {
5
+ const actual = humanize(new Date(10));
6
+ const expected = `Date(10)`;
7
+ assert({ actual, expected });
8
+ }
9
+
10
+ {
11
+ const nowMs = Date.now();
12
+ const actual = humanize(new Date(nowMs));
13
+ const expected = `Date(${nowMs})`;
14
+ assert({ actual, expected });
15
+ }
@@ -0,0 +1,33 @@
1
+ import { assert } from "@jsenv/assert";
2
+ import { humanize } from "@jsenv/humanize";
3
+
4
+ {
5
+ const actual = humanize(new Error("here"));
6
+ const expected = `Error("here")`;
7
+ assert({ actual, expected });
8
+ }
9
+
10
+ {
11
+ const actual = humanize(new RangeError("here"));
12
+ const expected = `RangeError("here")`;
13
+ assert({ actual, expected });
14
+ }
15
+
16
+ {
17
+ const actualError = new Error("hello");
18
+ Object.defineProperty(actualError, "bar", {
19
+ enumerable: false,
20
+ value: "bar",
21
+ });
22
+ const actual = humanize(actualError);
23
+ const expected = `Error("hello")`;
24
+ assert({ actual, expected });
25
+ }
26
+
27
+ {
28
+ const error = new Error();
29
+ error.name = "AssertionError";
30
+ const actual = humanize(error);
31
+ const expected = `Error("")`;
32
+ assert({ actual, expected });
33
+ }
@@ -0,0 +1,51 @@
1
+ import { assert } from "@jsenv/assert";
2
+ import { humanize } from "@jsenv/humanize";
3
+
4
+ // const arrowFunctionSupported = (() => {}).prototype === null
5
+
6
+ {
7
+ const actual = humanize(function () {});
8
+ const expected = `function () {/* hidden */}`;
9
+ assert({ actual, expected });
10
+ }
11
+
12
+ {
13
+ const actual = humanize(function () {}, { showFunctionBody: true });
14
+ const expected = "function () {}";
15
+ assert({ actual, expected });
16
+ }
17
+
18
+ {
19
+ const value = function () {
20
+ return true;
21
+ };
22
+ const actual = humanize(value, { showFunctionBody: true });
23
+ const expected = value.toString();
24
+ assert({ actual, expected });
25
+ }
26
+
27
+ function named(a) {
28
+ return a;
29
+ }
30
+ {
31
+ const actual = humanize(named);
32
+ const expected = `function named() {/* hidden */}`;
33
+ assert({ actual, expected });
34
+ }
35
+ {
36
+ const actual = humanize(named, { showFunctionBody: true });
37
+ const expected = named.toString();
38
+ assert({ actual, expected });
39
+ }
40
+
41
+ {
42
+ const nested = {
43
+ // eslint-disable-next-line object-shorthand
44
+ function: function () {},
45
+ };
46
+ const actual = humanize(nested);
47
+ const expected = `{
48
+ "function": function () {/* hidden */}
49
+ }`;
50
+ assert({ actual, expected });
51
+ }
@@ -0,0 +1,12 @@
1
+ import { assert } from "@jsenv/assert";
2
+ import { humanize } from "@jsenv/humanize";
3
+
4
+ const CustomConstructor = function () {
5
+ this.foo = true;
6
+ };
7
+ const customInstance = new CustomConstructor();
8
+ const actual = humanize(customInstance);
9
+ const expected = `CustomConstructor({
10
+ "foo": true
11
+ })`;
12
+ assert({ actual, expected });
@@ -0,0 +1,6 @@
1
+ import { assert } from "@jsenv/assert";
2
+ import { humanize } from "@jsenv/humanize";
3
+
4
+ const actual = humanize(null);
5
+ const expected = "null";
6
+ assert({ actual, expected });