@jsenv/humanize 1.0.0 → 1.1.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 (39) hide show
  1. package/README.md +25 -10
  2. package/dist/browser/jsenv_humanize_browser.js +76 -2
  3. package/dist/node/jsenv_humanize_node.js +73 -147
  4. package/package.json +3 -3
  5. package/src/.jsenv/jsenv_tests_output.txt +26 -29
  6. package/src/_tests/byte/file_size.test.js +2 -2
  7. package/src/_tests/byte/memory.test.js +11 -0
  8. package/src/_tests/js_value/array.test.js +14 -14
  9. package/src/_tests/js_value/biginit.test.js +10 -10
  10. package/src/_tests/js_value/boolean.test.js +12 -12
  11. package/src/_tests/js_value/date.test.js +4 -4
  12. package/src/_tests/js_value/error.test.js +8 -8
  13. package/src/_tests/js_value/function.test.js +12 -12
  14. package/src/_tests/js_value/instance.test.js +2 -2
  15. package/src/_tests/js_value/null.test.js +2 -2
  16. package/src/_tests/js_value/number.test.js +54 -54
  17. package/src/_tests/js_value/object.test.js +34 -34
  18. package/src/_tests/js_value/regexp.test.js +4 -4
  19. package/src/_tests/js_value/string.test.js +32 -32
  20. package/src/_tests/js_value/symbol.test.js +6 -6
  21. package/src/_tests/js_value/undefined.test.js +2 -2
  22. package/src/_tests/log/logger.test.mjs +14 -14
  23. package/src/_tests/log/spinner.test.mjs +6 -6
  24. package/src/_tests/percentage/percentage_distribution.test.mjs +2 -2
  25. package/src/_tests/time/decimals.test.js +40 -40
  26. package/src/_tests/time/duration.test.js +2 -2
  27. package/src/_tests/time/ellapsed.test.js +2 -2
  28. package/src/byte/byte.js +1 -1
  29. package/src/js_value/humanize.js +1 -1
  30. package/src/log/ansi_browser.js +27 -0
  31. package/src/log/{ansi.js → ansi_node.js} +7 -2
  32. package/src/log/dynamic_log.js +6 -4
  33. package/src/log/spinner.js +1 -1
  34. package/src/log/task_log.js +1 -1
  35. package/src/log/unicode_browser.js +53 -0
  36. package/src/log/{unicode.js → unicode_node.js} +4 -1
  37. package/src/main_browser.js +4 -1
  38. package/src/main_node.js +3 -3
  39. package/src/_tests/byte/memory_usage.test.js +0 -11
@@ -5,32 +5,32 @@ import { humanize } from "@jsenv/humanize";
5
5
  {
6
6
  const value = BigInt(1);
7
7
  const actual = humanize(value);
8
- const expected = "1n";
9
- assert({ actual, expected });
8
+ const expect = "1n";
9
+ assert({ actual, expect });
10
10
  }
11
11
 
12
12
  {
13
13
  const value = 2n;
14
14
  const actual = humanize(value);
15
- const expected = "2n";
16
- assert({ actual, expected });
15
+ const expect = "2n";
16
+ assert({ actual, expect });
17
17
  }
18
18
 
19
19
  {
20
20
  const value = Object(BigInt(1));
21
21
  const actual = humanize(value);
22
- const expected = "BigInt(1n)";
23
- assert({ actual, expected });
22
+ const expect = "BigInt(1n)";
23
+ assert({ actual, expect });
24
24
  }
25
25
 
26
26
  {
27
27
  const actual = humanize(1234567n);
28
- const expected = "1234567n";
29
- assert({ actual, expected });
28
+ const expect = "1234567n";
29
+ assert({ actual, expect });
30
30
  }
31
31
 
32
32
  {
33
33
  const actual = humanize(19223n);
34
- const expected = "19223n";
35
- assert({ actual, expected });
34
+ const expect = "19223n";
35
+ assert({ actual, expect });
36
36
  }
@@ -3,33 +3,33 @@ import { humanize } from "@jsenv/humanize";
3
3
 
4
4
  {
5
5
  const actual = humanize(true);
6
- const expected = "true";
7
- assert({ actual, expected });
6
+ const expect = "true";
7
+ assert({ actual, expect });
8
8
  }
9
9
 
10
10
  {
11
11
  const actual = humanize(false);
12
- const expected = "false";
13
- assert({ actual, expected });
12
+ const expect = "false";
13
+ assert({ actual, expect });
14
14
  }
15
15
 
16
16
  /* eslint-disable no-new-wrappers */
17
17
  {
18
18
  const actual = humanize(new Boolean(true));
19
- const expected = "Boolean(true)";
20
- assert({ actual, expected });
19
+ const expect = "Boolean(true)";
20
+ assert({ actual, expect });
21
21
  }
22
22
 
23
23
  {
24
24
  const actual = humanize(new Boolean(true), { parenthesis: true });
25
- const expected = "(Boolean(true))";
26
- assert({ actual, expected });
25
+ const expect = "(Boolean(true))";
26
+ assert({ actual, expect });
27
27
  }
28
28
 
29
29
  {
30
30
  const actual = humanize(new Boolean(true), { useNew: true });
31
- const expected = "new Boolean(true)";
32
- assert({ actual, expected });
31
+ const expect = "new Boolean(true)";
32
+ assert({ actual, expect });
33
33
  }
34
34
 
35
35
  {
@@ -37,9 +37,9 @@ import { humanize } from "@jsenv/humanize";
37
37
  parenthesis: true,
38
38
  useNew: true,
39
39
  });
40
- const expected = "new (Boolean(true))";
40
+ const expect = "new (Boolean(true))";
41
41
  assert({
42
42
  actual,
43
- expected,
43
+ expect,
44
44
  });
45
45
  }
@@ -3,13 +3,13 @@ import { humanize } from "@jsenv/humanize";
3
3
 
4
4
  {
5
5
  const actual = humanize(new Date(10));
6
- const expected = `Date(10)`;
7
- assert({ actual, expected });
6
+ const expect = `Date(10)`;
7
+ assert({ actual, expect });
8
8
  }
9
9
 
10
10
  {
11
11
  const nowMs = Date.now();
12
12
  const actual = humanize(new Date(nowMs));
13
- const expected = `Date(${nowMs})`;
14
- assert({ actual, expected });
13
+ const expect = `Date(${nowMs})`;
14
+ assert({ actual, expect });
15
15
  }
@@ -3,14 +3,14 @@ import { humanize } from "@jsenv/humanize";
3
3
 
4
4
  {
5
5
  const actual = humanize(new Error("here"));
6
- const expected = `Error("here")`;
7
- assert({ actual, expected });
6
+ const expect = `Error("here")`;
7
+ assert({ actual, expect });
8
8
  }
9
9
 
10
10
  {
11
11
  const actual = humanize(new RangeError("here"));
12
- const expected = `RangeError("here")`;
13
- assert({ actual, expected });
12
+ const expect = `RangeError("here")`;
13
+ assert({ actual, expect });
14
14
  }
15
15
 
16
16
  {
@@ -20,14 +20,14 @@ import { humanize } from "@jsenv/humanize";
20
20
  value: "bar",
21
21
  });
22
22
  const actual = humanize(actualError);
23
- const expected = `Error("hello")`;
24
- assert({ actual, expected });
23
+ const expect = `Error("hello")`;
24
+ assert({ actual, expect });
25
25
  }
26
26
 
27
27
  {
28
28
  const error = new Error();
29
29
  error.name = "AssertionError";
30
30
  const actual = humanize(error);
31
- const expected = `Error("")`;
32
- assert({ actual, expected });
31
+ const expect = `Error("")`;
32
+ assert({ actual, expect });
33
33
  }
@@ -5,14 +5,14 @@ import { humanize } from "@jsenv/humanize";
5
5
 
6
6
  {
7
7
  const actual = humanize(function () {});
8
- const expected = `function () {/* hidden */}`;
9
- assert({ actual, expected });
8
+ const expect = `function () {/* hidden */}`;
9
+ assert({ actual, expect });
10
10
  }
11
11
 
12
12
  {
13
13
  const actual = humanize(function () {}, { showFunctionBody: true });
14
- const expected = "function () {}";
15
- assert({ actual, expected });
14
+ const expect = "function () {}";
15
+ assert({ actual, expect });
16
16
  }
17
17
 
18
18
  {
@@ -20,8 +20,8 @@ import { humanize } from "@jsenv/humanize";
20
20
  return true;
21
21
  };
22
22
  const actual = humanize(value, { showFunctionBody: true });
23
- const expected = value.toString();
24
- assert({ actual, expected });
23
+ const expect = value.toString();
24
+ assert({ actual, expect });
25
25
  }
26
26
 
27
27
  function named(a) {
@@ -29,13 +29,13 @@ function named(a) {
29
29
  }
30
30
  {
31
31
  const actual = humanize(named);
32
- const expected = `function named() {/* hidden */}`;
33
- assert({ actual, expected });
32
+ const expect = `function named() {/* hidden */}`;
33
+ assert({ actual, expect });
34
34
  }
35
35
  {
36
36
  const actual = humanize(named, { showFunctionBody: true });
37
- const expected = named.toString();
38
- assert({ actual, expected });
37
+ const expect = named.toString();
38
+ assert({ actual, expect });
39
39
  }
40
40
 
41
41
  {
@@ -44,8 +44,8 @@ function named(a) {
44
44
  function: function () {},
45
45
  };
46
46
  const actual = humanize(nested);
47
- const expected = `{
47
+ const expect = `{
48
48
  "function": function () {/* hidden */}
49
49
  }`;
50
- assert({ actual, expected });
50
+ assert({ actual, expect });
51
51
  }
@@ -6,7 +6,7 @@ const CustomConstructor = function () {
6
6
  };
7
7
  const customInstance = new CustomConstructor();
8
8
  const actual = humanize(customInstance);
9
- const expected = `CustomConstructor({
9
+ const expect = `CustomConstructor({
10
10
  "foo": true
11
11
  })`;
12
- assert({ actual, expected });
12
+ assert({ actual, expect });
@@ -2,5 +2,5 @@ import { assert } from "@jsenv/assert";
2
2
  import { humanize } from "@jsenv/humanize";
3
3
 
4
4
  const actual = humanize(null);
5
- const expected = "null";
6
- assert({ actual, expected });
5
+ const expect = "null";
6
+ assert({ actual, expect });
@@ -5,178 +5,178 @@ import { humanize } from "@jsenv/humanize";
5
5
 
6
6
  {
7
7
  const actual = humanize(0);
8
- const expected = "0";
9
- assert({ actual, expected });
8
+ const expect = "0";
9
+ assert({ actual, expect });
10
10
  }
11
11
 
12
12
  {
13
13
  const actual = humanize(1);
14
- const expected = "1";
15
- assert({ actual, expected });
14
+ const expect = "1";
15
+ assert({ actual, expect });
16
16
  }
17
17
 
18
18
  {
19
19
  const actual = humanize(-0);
20
- const expected = "-0";
21
- assert({ actual, expected });
20
+ const expect = "-0";
21
+ assert({ actual, expect });
22
22
  }
23
23
 
24
24
  {
25
25
  const actual = humanize(NaN);
26
- const expected = "NaN";
27
- assert({ actual, expected });
26
+ const expect = "NaN";
27
+ assert({ actual, expect });
28
28
  }
29
29
 
30
30
  {
31
31
  const actual = humanize(Infinity);
32
- const expected = "Infinity";
33
- assert({ actual, expected });
32
+ const expect = "Infinity";
33
+ assert({ actual, expect });
34
34
  }
35
35
 
36
36
  {
37
37
  const actual = humanize(-Infinity);
38
- const expected = "-Infinity";
39
- assert({ actual, expected });
38
+ const expect = "-Infinity";
39
+ assert({ actual, expect });
40
40
  }
41
41
 
42
42
  {
43
43
  // eslint-disable-next-line no-new-wrappers
44
44
  const actual = humanize(new Number(0));
45
- const expected = "Number(0)";
46
- assert({ actual, expected });
45
+ const expect = "Number(0)";
46
+ assert({ actual, expect });
47
47
  }
48
48
 
49
49
  {
50
50
  // eslint-disable-next-line no-new-wrappers
51
51
  const actual = humanize(new Number(0), { parenthesis: true });
52
- const expected = "(Number(0))";
53
- assert({ actual, expected });
52
+ const expect = "(Number(0))";
53
+ assert({ actual, expect });
54
54
  }
55
55
 
56
56
  {
57
57
  // eslint-disable-next-line no-new-wrappers
58
58
  const actual = humanize(new Number(0), { useNew: true });
59
- const expected = "new Number(0)";
60
- assert({ actual, expected });
59
+ const expect = "new Number(0)";
60
+ assert({ actual, expect });
61
61
  }
62
62
 
63
63
  {
64
64
  // eslint-disable-next-line no-new-wrappers
65
65
  const actual = humanize(new Number(0), { parenthesis: true, useNew: true });
66
- const expected = "new (Number(0))";
67
- assert({ actual, expected });
66
+ const expect = "new (Number(0))";
67
+ assert({ actual, expect });
68
68
  }
69
69
 
70
70
  // numeric separator - numbers
71
71
  {
72
72
  const actual = humanize(1235);
73
- const expected = "1235";
74
- assert({ actual, expected });
73
+ const expect = "1235";
74
+ assert({ actual, expect });
75
75
  }
76
76
 
77
77
  {
78
78
  const actual = humanize(67000);
79
- const expected = "67_000";
80
- assert({ actual, expected });
79
+ const expect = "67_000";
80
+ assert({ actual, expect });
81
81
  }
82
82
 
83
83
  {
84
84
  const actual = humanize(149600000);
85
- const expected = "149_600_000";
86
- assert({ actual, expected });
85
+ const expect = "149_600_000";
86
+ assert({ actual, expect });
87
87
  }
88
88
 
89
89
  {
90
90
  const actual = humanize(1_464_301);
91
- const expected = "1_464_301";
92
- assert({ actual, expected });
91
+ const expect = "1_464_301";
92
+ assert({ actual, expect });
93
93
  }
94
94
 
95
95
  // decimal
96
96
  {
97
97
  const actual = humanize(1234.56);
98
- const expected = "1234.56";
99
- assert({ actual, expected });
98
+ const expect = "1234.56";
99
+ assert({ actual, expect });
100
100
  }
101
101
 
102
102
  {
103
103
  const actual = humanize(12345.67);
104
- const expected = "12_345.67";
105
- assert({ actual, expected });
104
+ const expect = "12_345.67";
105
+ assert({ actual, expect });
106
106
  }
107
107
 
108
108
  {
109
109
  const actual = humanize(-0.120123);
110
- const expected = "-0.120123";
111
- assert({ actual, expected });
110
+ const expect = "-0.120123";
111
+ assert({ actual, expect });
112
112
  }
113
113
 
114
114
  // negative
115
115
  {
116
116
  const actual = humanize(-1000001);
117
- const expected = "-1_000_001";
118
- assert({ actual, expected });
117
+ const expect = "-1_000_001";
118
+ assert({ actual, expect });
119
119
  }
120
120
 
121
121
  // exponential
122
122
  {
123
123
  const actual = humanize(-1.23456e105);
124
- const expected = "-1.23456e+105";
125
- assert({ actual, expected });
124
+ const expect = "-1.23456e+105";
125
+ assert({ actual, expect });
126
126
  }
127
127
 
128
128
  {
129
129
  const actual = humanize(-1200000e5);
130
- const expected = "-120_000_000_000";
131
- assert({ actual, expected });
130
+ const expect = "-120_000_000_000";
131
+ assert({ actual, expect });
132
132
  }
133
133
 
134
134
  {
135
135
  // prettier-ignore
136
136
  const actual = humanize(3.65432E12)
137
- const expected = "3_654_320_000_000";
138
- assert({ actual, expected });
137
+ const expect = "3_654_320_000_000";
138
+ assert({ actual, expect });
139
139
  }
140
140
 
141
141
  // numeric separator - binary
142
142
  {
143
143
  const actual = humanize(0b10101010101010);
144
- const expected = "10_922";
145
- assert({ actual, expected });
144
+ const expect = "10_922";
145
+ assert({ actual, expect });
146
146
  }
147
147
 
148
148
  {
149
149
  // prettier-ignore
150
150
  const actual = humanize(0B10101010101010)
151
- const expected = "10_922";
152
- assert({ actual, expected });
151
+ const expect = "10_922";
152
+ assert({ actual, expect });
153
153
  }
154
154
 
155
155
  // numeric separator - hexadecimal
156
156
  {
157
157
  const actual = humanize(0xfabf00d);
158
- const expected = "262_926_349";
159
- assert({ actual, expected });
158
+ const expect = "262_926_349";
159
+ assert({ actual, expect });
160
160
  }
161
161
 
162
162
  {
163
163
  // prettier-ignore
164
164
  const actual = humanize(0xABCDEF)
165
165
  // prettier-ignore
166
- const expected = "11_259_375"
167
- assert({ actual, expected });
166
+ const expect = "11_259_375"
167
+ assert({ actual, expect });
168
168
  }
169
169
 
170
170
  // numeric separator - octal
171
171
  {
172
172
  const actual = humanize(0o010101010101);
173
- const expected = "1_090_785_345";
174
- assert({ actual, expected });
173
+ const expect = "1_090_785_345";
174
+ assert({ actual, expect });
175
175
  }
176
176
 
177
177
  {
178
178
  // prettier-ignore
179
179
  const actual = humanize(0O010101010101)
180
- const expected = "1_090_785_345";
181
- assert({ actual, expected });
180
+ const expect = "1_090_785_345";
181
+ assert({ actual, expect });
182
182
  }
@@ -3,21 +3,21 @@ import { humanize } from "@jsenv/humanize";
3
3
 
4
4
  {
5
5
  const actual = humanize({});
6
- const expected = "{}";
7
- assert({ actual, expected });
6
+ const expect = "{}";
7
+ assert({ actual, expect });
8
8
  }
9
9
 
10
10
  {
11
11
  // eslint-disable-next-line no-new-object
12
12
  const actual = humanize(new Object({}));
13
- const expected = "{}";
14
- assert({ actual, expected });
13
+ const expect = "{}";
14
+ assert({ actual, expect });
15
15
  }
16
16
 
17
17
  {
18
18
  const actual = humanize({}, { objectConstructor: true });
19
- const expected = "Object({})";
20
- assert({ actual, expected });
19
+ const expect = "Object({})";
20
+ assert({ actual, expect });
21
21
  }
22
22
 
23
23
  {
@@ -25,37 +25,37 @@ import { humanize } from "@jsenv/humanize";
25
25
  { foo: true },
26
26
  { objectConstructor: true, useNew: true },
27
27
  );
28
- const expected = `new Object({
28
+ const expect = `new Object({
29
29
  "foo": true
30
30
  })`;
31
31
  assert({
32
32
  actual,
33
- expected,
33
+ expect,
34
34
  });
35
35
  }
36
36
 
37
37
  {
38
38
  const actual = humanize({ 0: "foo" });
39
- const expected = `{
39
+ const expect = `{
40
40
  0: "foo"
41
41
  }`;
42
- assert({ actual, expected });
42
+ assert({ actual, expect });
43
43
  }
44
44
 
45
45
  {
46
46
  const actual = humanize({ Infinity: "foo" });
47
- const expected = `{
47
+ const expect = `{
48
48
  "Infinity": "foo"
49
49
  }`;
50
- assert({ actual, expected });
50
+ assert({ actual, expect });
51
51
  }
52
52
 
53
53
  {
54
54
  const actual = humanize({ name: "dam" }, { quote: "'" });
55
- const expected = `{
55
+ const expect = `{
56
56
  'name': 'dam'
57
57
  }`;
58
- assert({ actual, expected });
58
+ assert({ actual, expect });
59
59
  }
60
60
 
61
61
  {
@@ -63,24 +63,24 @@ import { humanize } from "@jsenv/humanize";
63
63
  { foo: true, nested: { bar: true } },
64
64
  { parenthesis: true },
65
65
  );
66
- const expected = `({
66
+ const expect = `({
67
67
  "foo": true,
68
68
  "nested": ({
69
69
  "bar": true
70
70
  })
71
71
  })`;
72
- assert({ actual, expected });
72
+ assert({ actual, expect });
73
73
  }
74
74
 
75
75
  {
76
76
  const foo = { foo: true, bar: false };
77
77
 
78
78
  const actual = humanize(foo);
79
- const expected = `{
79
+ const expect = `{
80
80
  "foo": true,
81
81
  "bar": false
82
82
  }`;
83
- assert({ actual, expected });
83
+ assert({ actual, expect });
84
84
  }
85
85
 
86
86
  {
@@ -89,19 +89,19 @@ import { humanize } from "@jsenv/humanize";
89
89
  foo: true,
90
90
  }),
91
91
  );
92
- const expected = "{}";
93
- assert({ actual, expected });
92
+ const expect = "{}";
93
+ assert({ actual, expect });
94
94
  }
95
95
 
96
96
  {
97
97
  const nested = { foo: { name: "dam" } };
98
98
  const actual = humanize(nested);
99
- const expected = `{
99
+ const expect = `{
100
100
  "foo": {
101
101
  "name": "dam"
102
102
  }
103
103
  }`;
104
- assert({ actual, expected });
104
+ assert({ actual, expect });
105
105
  }
106
106
 
107
107
  {
@@ -110,11 +110,11 @@ import { humanize } from "@jsenv/humanize";
110
110
  };
111
111
  circularObject.self = circularObject;
112
112
  const actual = humanize(circularObject);
113
- const expected = `{
113
+ const expect = `{
114
114
  "foo": true,
115
115
  "self": Symbol.for('circular')
116
116
  }`;
117
- assert({ actual, expected });
117
+ assert({ actual, expect });
118
118
  }
119
119
 
120
120
  {
@@ -126,30 +126,30 @@ import { humanize } from "@jsenv/humanize";
126
126
  parent: nestedCircularObject,
127
127
  };
128
128
  const actual = humanize(nestedCircularObject);
129
- const expected = `{
129
+ const expect = `{
130
130
  "foo": true,
131
131
  "nested": {
132
132
  "bar": true,
133
133
  "parent": Symbol.for('circular')
134
134
  }
135
135
  }`;
136
- assert({ actual, expected });
136
+ assert({ actual, expect });
137
137
  }
138
138
 
139
139
  {
140
140
  const actual = humanize(Object.create(null));
141
- const expected = "{}";
142
- assert({ actual, expected });
141
+ const expect = "{}";
142
+ assert({ actual, expect });
143
143
  }
144
144
 
145
145
  {
146
146
  const object = Object.create(null);
147
147
  object[Symbol.toStringTag] = "stuff";
148
148
  const actual = humanize(object);
149
- const expected = `{
149
+ const expect = `{
150
150
  [Symbol("Symbol.toStringTag")]: "stuff"
151
151
  }`;
152
- assert({ actual, expected });
152
+ assert({ actual, expect });
153
153
  }
154
154
 
155
155
  {
@@ -157,17 +157,17 @@ import { humanize } from "@jsenv/humanize";
157
157
  object[Symbol.toStringTag] = "stuff";
158
158
  object.foo = true;
159
159
  const actual = humanize(object);
160
- const expected = `{
160
+ const expect = `{
161
161
  "foo": true,
162
162
  [Symbol("Symbol.toStringTag")]: "stuff"
163
163
  }`;
164
- assert({ actual, expected });
164
+ assert({ actual, expect });
165
165
  }
166
166
 
167
167
  {
168
168
  const actual = humanize({ [Symbol()]: true });
169
- const expected = `{
169
+ const expect = `{
170
170
  [Symbol()]: true
171
171
  }`;
172
- assert({ actual, expected });
172
+ assert({ actual, expect });
173
173
  }
@@ -3,12 +3,12 @@ import { humanize } from "@jsenv/humanize";
3
3
 
4
4
  {
5
5
  const actual = humanize(/ok/g);
6
- const expected = "/ok/g";
7
- assert({ actual, expected });
6
+ const expect = "/ok/g";
7
+ assert({ actual, expect });
8
8
  }
9
9
 
10
10
  {
11
11
  const actual = humanize(new RegExp("foo", "g"));
12
- const expected = "/foo/g";
13
- assert({ actual, expected });
12
+ const expect = "/foo/g";
13
+ assert({ actual, expect });
14
14
  }