@jsenv/humanize 1.0.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/README.md +25 -10
- package/dist/browser/jsenv_humanize_browser.js +96 -2
- package/dist/node/jsenv_humanize_node.js +1470 -1531
- package/package.json +3 -3
- package/src/.jsenv/jsenv_tests_output.txt +27 -30
- package/src/_tests/byte/file_size.test.js +2 -2
- package/src/_tests/byte/memory.test.js +11 -0
- package/src/_tests/js_value/array.test.js +14 -14
- package/src/_tests/js_value/biginit.test.js +10 -10
- package/src/_tests/js_value/boolean.test.js +12 -12
- package/src/_tests/js_value/date.test.js +4 -4
- package/src/_tests/js_value/error.test.js +8 -8
- package/src/_tests/js_value/function.test.js +12 -12
- package/src/_tests/js_value/instance.test.js +2 -2
- package/src/_tests/js_value/null.test.js +2 -2
- package/src/_tests/js_value/number.test.js +54 -54
- package/src/_tests/js_value/object.test.js +34 -34
- package/src/_tests/js_value/regexp.test.js +4 -4
- package/src/_tests/js_value/string.test.js +32 -32
- package/src/_tests/js_value/symbol.test.js +6 -6
- package/src/_tests/js_value/undefined.test.js +2 -2
- package/src/_tests/log/logger.test.mjs +14 -14
- package/src/_tests/log/spinner.test.mjs +6 -6
- package/src/_tests/percentage/percentage_distribution.test.mjs +2 -2
- package/src/_tests/time/decimals.test.js +40 -40
- package/src/_tests/time/duration.test.js +2 -2
- package/src/_tests/time/ellapsed.test.js +2 -2
- package/src/ansi/ansi_browser.js +3 -0
- package/src/ansi/ansi_node.js +16 -0
- package/src/ansi/ansi_runtime_agnostic.js +33 -0
- package/src/byte/byte.js +1 -1
- package/src/js_value/humanize.js +1 -1
- package/src/js_value/string.js +1 -1
- package/src/log/dynamic_log.js +6 -4
- package/src/log/spinner.js +1 -1
- package/src/log/task_log.js +1 -1
- package/src/main_browser.js +3 -5
- package/src/main_node.js +9 -13
- package/src/unicode/unicode_browser.js +7 -0
- package/src/unicode/unicode_node.js +8 -0
- package/src/unicode/unicode_runtime_agnostic.js +53 -0
- package/src/_tests/byte/memory_usage.test.js +0 -11
- package/src/log/ansi.js +0 -37
- package/src/log/unicode.js +0 -52
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/humanize",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Generate messages meant to read by humans",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"prepublishOnly": "npm run build"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"string-width": "7.
|
|
42
|
+
"string-width": "7.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"ansi-escapes": "
|
|
45
|
+
"ansi-escapes": "7.0.0",
|
|
46
46
|
"is-unicode-supported": "2.0.0",
|
|
47
47
|
"supports-color": "9.4.0"
|
|
48
48
|
}
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
1 with chromium (chromium@120.0.6099.28)
|
|
4
|
-
1 with firefox (firefox@119.0)
|
|
5
|
-
1 with webkit (webkit@17.4)
|
|
1
|
+
-------------- execution start --------------
|
|
2
|
+
21 files matching "testPlan" in /Users/damien.maillard/dev/perso/jsenv-core/packages/independent/humanize/src
|
|
6
3
|
---------------------------------------------
|
|
7
4
|
|
|
8
|
-
✔ 01/23 _tests/byte/file_size.test.js [node/0.03s
|
|
9
|
-
✔ 02/23 _tests/byte/
|
|
10
|
-
✔ 03/23 _tests/content_frame/content_frame.test.js [node/0.
|
|
11
|
-
✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.2s
|
|
12
|
-
✔ 05/23 _tests/js_value/_inspect.test.html [firefox/0.
|
|
13
|
-
✔ 06/23 _tests/js_value/_inspect.test.html [webkit/0.
|
|
14
|
-
✔ 07/23 _tests/js_value/array.test.js [node/0.
|
|
15
|
-
✔ 08/23 _tests/js_value/biginit.test.js [node/0.
|
|
16
|
-
✔ 09/23 _tests/js_value/boolean.test.js [node/0.
|
|
17
|
-
✔ 10/23 _tests/js_value/date.test.js [node/0.
|
|
18
|
-
✔ 11/23 _tests/js_value/error.test.js [node/0.
|
|
19
|
-
✔ 12/23 _tests/js_value/function.test.js [node/0.
|
|
20
|
-
✔ 13/23 _tests/js_value/instance.test.js [node/0.
|
|
21
|
-
✔ 14/23 _tests/js_value/null.test.js [node/0.
|
|
22
|
-
✔ 15/23 _tests/js_value/number.test.js [node/0.06s
|
|
23
|
-
✔ 16/23 _tests/js_value/object.test.js [node/0.
|
|
24
|
-
✔ 17/23 _tests/js_value/regexp.test.js [node/0.05s
|
|
25
|
-
✔ 18/23 _tests/js_value/string.test.js [node/0.
|
|
26
|
-
✔ 19/23 _tests/js_value/symbol.test.js [node/0.
|
|
27
|
-
✔ 20/23 _tests/js_value/undefined.test.js [node/0.
|
|
28
|
-
✔ 21/23 _tests/time/decimals.test.js [node/0.
|
|
29
|
-
✔ 22/23 _tests/time/duration.test.js [node/0.03s
|
|
30
|
-
✔ 23/23 _tests/time/ellapsed.test.js [node/0.02s
|
|
5
|
+
✔ 01/23 _tests/byte/file_size.test.js [node/0.03s] (1 completed)
|
|
6
|
+
✔ 02/23 _tests/byte/memory.test.js [node/0.03s] (2 completed)
|
|
7
|
+
✔ 03/23 _tests/content_frame/content_frame.test.js [node/0.07s] (3 completed)
|
|
8
|
+
✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.2s] (4 completed)
|
|
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.2s] (6 completed)
|
|
11
|
+
✔ 07/23 _tests/js_value/array.test.js [node/0.03s] (7 completed)
|
|
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.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
|
+
✔ 15/23 _tests/js_value/number.test.js [node/0.06s] (15 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
|
+
✔ 22/23 _tests/time/duration.test.js [node/0.03s] (22 completed)
|
|
27
|
+
✔ 23/23 _tests/time/ellapsed.test.js [node/0.02s] (all completed)
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
--------------- execution end ---------------
|
|
33
30
|
23 executions: all completed
|
|
34
|
-
duration:
|
|
31
|
+
duration: 2.4s (setup: 0.4s, execution: 2.3s, teardown: 0.2s)
|
|
35
32
|
---------------------------------------------
|
|
@@ -2,9 +2,9 @@ import { assert } from "@jsenv/assert";
|
|
|
2
2
|
|
|
3
3
|
import { humanizeFileSize } from "@jsenv/humanize";
|
|
4
4
|
|
|
5
|
-
const test = (fileSize,
|
|
5
|
+
const test = (fileSize, expect) => {
|
|
6
6
|
const actual = humanizeFileSize(fileSize);
|
|
7
|
-
assert({ actual,
|
|
7
|
+
assert({ actual, expect });
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
test(0, "0 B");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert";
|
|
2
|
+
|
|
3
|
+
import { humanizeMemory } from "@jsenv/humanize";
|
|
4
|
+
|
|
5
|
+
const test = (memoryUsageInBytes, expect) => {
|
|
6
|
+
const actual = humanizeMemory(memoryUsageInBytes);
|
|
7
|
+
assert({ actual, expect });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
test(1000, "1.0 kB");
|
|
11
|
+
test(1100, "1.1 kB");
|
|
@@ -3,35 +3,35 @@ import { humanize } from "@jsenv/humanize";
|
|
|
3
3
|
|
|
4
4
|
{
|
|
5
5
|
const actual = humanize([]);
|
|
6
|
-
const
|
|
7
|
-
assert({ actual,
|
|
6
|
+
const expect = `[]`;
|
|
7
|
+
assert({ actual, expect });
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
{
|
|
11
11
|
const actual = humanize([[]]);
|
|
12
|
-
const
|
|
12
|
+
const expect = `[
|
|
13
13
|
[]
|
|
14
14
|
]`;
|
|
15
|
-
assert({ actual,
|
|
15
|
+
assert({ actual, expect });
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
{
|
|
19
19
|
const actual = humanize(Array(3));
|
|
20
20
|
// prettier-ignore
|
|
21
|
-
const
|
|
21
|
+
const expect = `[
|
|
22
22
|
,
|
|
23
23
|
,
|
|
24
24
|
${" "}
|
|
25
25
|
]`
|
|
26
|
-
assert({ actual,
|
|
26
|
+
assert({ actual, expect });
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
{
|
|
30
30
|
const actual = humanize([Symbol()]);
|
|
31
|
-
const
|
|
31
|
+
const expect = `[
|
|
32
32
|
Symbol()
|
|
33
33
|
]`;
|
|
34
|
-
assert({ actual,
|
|
34
|
+
assert({ actual, expect });
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
{
|
|
@@ -40,23 +40,23 @@ ${" "}
|
|
|
40
40
|
|
|
41
41
|
{
|
|
42
42
|
const actual = humanize(newArray);
|
|
43
|
-
const
|
|
43
|
+
const expect = `[
|
|
44
44
|
"foo",
|
|
45
45
|
1
|
|
46
46
|
]`;
|
|
47
47
|
assert({
|
|
48
48
|
actual,
|
|
49
|
-
|
|
49
|
+
expect,
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
{
|
|
54
54
|
const actual = humanize(newArray);
|
|
55
|
-
const
|
|
55
|
+
const expect = `[
|
|
56
56
|
"foo",
|
|
57
57
|
1
|
|
58
58
|
]`;
|
|
59
|
-
assert({ actual,
|
|
59
|
+
assert({ actual, expect });
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -64,9 +64,9 @@ ${" "}
|
|
|
64
64
|
const circularArray = [0];
|
|
65
65
|
circularArray.push(circularArray);
|
|
66
66
|
const actual = humanize(circularArray);
|
|
67
|
-
const
|
|
67
|
+
const expect = `[
|
|
68
68
|
0,
|
|
69
69
|
Symbol.for('circular')
|
|
70
70
|
]`;
|
|
71
|
-
assert({ actual,
|
|
71
|
+
assert({ actual, expect });
|
|
72
72
|
}
|
|
@@ -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
|
|
9
|
-
assert({ actual,
|
|
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
|
|
16
|
-
assert({ actual,
|
|
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
|
|
23
|
-
assert({ actual,
|
|
22
|
+
const expect = "BigInt(1n)";
|
|
23
|
+
assert({ actual, expect });
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
{
|
|
27
27
|
const actual = humanize(1234567n);
|
|
28
|
-
const
|
|
29
|
-
assert({ actual,
|
|
28
|
+
const expect = "1234567n";
|
|
29
|
+
assert({ actual, expect });
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
{
|
|
33
33
|
const actual = humanize(19223n);
|
|
34
|
-
const
|
|
35
|
-
assert({ actual,
|
|
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
|
|
7
|
-
assert({ actual,
|
|
6
|
+
const expect = "true";
|
|
7
|
+
assert({ actual, expect });
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
{
|
|
11
11
|
const actual = humanize(false);
|
|
12
|
-
const
|
|
13
|
-
assert({ actual,
|
|
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
|
|
20
|
-
assert({ actual,
|
|
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
|
|
26
|
-
assert({ actual,
|
|
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
|
|
32
|
-
assert({ actual,
|
|
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
|
|
40
|
+
const expect = "new (Boolean(true))";
|
|
41
41
|
assert({
|
|
42
42
|
actual,
|
|
43
|
-
|
|
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
|
|
7
|
-
assert({ actual,
|
|
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
|
|
14
|
-
assert({ actual,
|
|
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
|
|
7
|
-
assert({ actual,
|
|
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
|
|
13
|
-
assert({ actual,
|
|
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
|
|
24
|
-
assert({ actual,
|
|
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
|
|
32
|
-
assert({ actual,
|
|
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
|
|
9
|
-
assert({ actual,
|
|
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
|
|
15
|
-
assert({ actual,
|
|
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
|
|
24
|
-
assert({ actual,
|
|
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
|
|
33
|
-
assert({ actual,
|
|
32
|
+
const expect = `function named() {/* hidden */}`;
|
|
33
|
+
assert({ actual, expect });
|
|
34
34
|
}
|
|
35
35
|
{
|
|
36
36
|
const actual = humanize(named, { showFunctionBody: true });
|
|
37
|
-
const
|
|
38
|
-
assert({ actual,
|
|
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
|
|
47
|
+
const expect = `{
|
|
48
48
|
"function": function () {/* hidden */}
|
|
49
49
|
}`;
|
|
50
|
-
assert({ actual,
|
|
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
|
|
9
|
+
const expect = `CustomConstructor({
|
|
10
10
|
"foo": true
|
|
11
11
|
})`;
|
|
12
|
-
assert({ actual,
|
|
12
|
+
assert({ actual, expect });
|
|
@@ -5,178 +5,178 @@ import { humanize } from "@jsenv/humanize";
|
|
|
5
5
|
|
|
6
6
|
{
|
|
7
7
|
const actual = humanize(0);
|
|
8
|
-
const
|
|
9
|
-
assert({ actual,
|
|
8
|
+
const expect = "0";
|
|
9
|
+
assert({ actual, expect });
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
{
|
|
13
13
|
const actual = humanize(1);
|
|
14
|
-
const
|
|
15
|
-
assert({ actual,
|
|
14
|
+
const expect = "1";
|
|
15
|
+
assert({ actual, expect });
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
{
|
|
19
19
|
const actual = humanize(-0);
|
|
20
|
-
const
|
|
21
|
-
assert({ actual,
|
|
20
|
+
const expect = "-0";
|
|
21
|
+
assert({ actual, expect });
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
{
|
|
25
25
|
const actual = humanize(NaN);
|
|
26
|
-
const
|
|
27
|
-
assert({ actual,
|
|
26
|
+
const expect = "NaN";
|
|
27
|
+
assert({ actual, expect });
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
{
|
|
31
31
|
const actual = humanize(Infinity);
|
|
32
|
-
const
|
|
33
|
-
assert({ actual,
|
|
32
|
+
const expect = "Infinity";
|
|
33
|
+
assert({ actual, expect });
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
{
|
|
37
37
|
const actual = humanize(-Infinity);
|
|
38
|
-
const
|
|
39
|
-
assert({ actual,
|
|
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
|
|
46
|
-
assert({ actual,
|
|
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
|
|
53
|
-
assert({ actual,
|
|
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
|
|
60
|
-
assert({ actual,
|
|
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
|
|
67
|
-
assert({ actual,
|
|
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
|
|
74
|
-
assert({ actual,
|
|
73
|
+
const expect = "1235";
|
|
74
|
+
assert({ actual, expect });
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
{
|
|
78
78
|
const actual = humanize(67000);
|
|
79
|
-
const
|
|
80
|
-
assert({ actual,
|
|
79
|
+
const expect = "67_000";
|
|
80
|
+
assert({ actual, expect });
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
{
|
|
84
84
|
const actual = humanize(149600000);
|
|
85
|
-
const
|
|
86
|
-
assert({ actual,
|
|
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
|
|
92
|
-
assert({ actual,
|
|
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
|
|
99
|
-
assert({ actual,
|
|
98
|
+
const expect = "1234.56";
|
|
99
|
+
assert({ actual, expect });
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
{
|
|
103
103
|
const actual = humanize(12345.67);
|
|
104
|
-
const
|
|
105
|
-
assert({ actual,
|
|
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
|
|
111
|
-
assert({ actual,
|
|
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
|
|
118
|
-
assert({ actual,
|
|
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
|
|
125
|
-
assert({ actual,
|
|
124
|
+
const expect = "-1.23456e+105";
|
|
125
|
+
assert({ actual, expect });
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
{
|
|
129
129
|
const actual = humanize(-1200000e5);
|
|
130
|
-
const
|
|
131
|
-
assert({ actual,
|
|
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
|
|
138
|
-
assert({ actual,
|
|
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
|
|
145
|
-
assert({ actual,
|
|
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
|
|
152
|
-
assert({ actual,
|
|
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
|
|
159
|
-
assert({ actual,
|
|
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
|
|
167
|
-
assert({ actual,
|
|
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
|
|
174
|
-
assert({ actual,
|
|
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
|
|
181
|
-
assert({ actual,
|
|
180
|
+
const expect = "1_090_785_345";
|
|
181
|
+
assert({ actual, expect });
|
|
182
182
|
}
|