@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.
- package/dist/browser/jsenv_humanize_browser.js +539 -482
- package/dist/browser/jsenv_humanize_browser.js.map +76 -0
- package/dist/node/jsenv_humanize_node.js +58 -7
- package/dist/node/jsenv_humanize_node.js.map +97 -0
- package/dist/node/jsenv_humanize_node_modules.js +23 -15
- package/dist/node/jsenv_humanize_node_modules.js.map +21 -0
- package/package.json +20 -17
- package/src/_tests/byte/file_size.test.js +0 -18
- package/src/_tests/byte/memory.test.js +0 -11
- package/src/_tests/content_frame/content_frame.test.js +0 -156
- package/src/_tests/content_frame/snapshots/10_line_and_column_are_zero.txt +0 -2
- package/src/_tests/content_frame/snapshots/11_line_is_last.txt +0 -3
- package/src/_tests/content_frame/snapshots/1_basic.txt +0 -4
- package/src/_tests/content_frame/snapshots/2_basic_2.txt +0 -6
- package/src/_tests/content_frame/snapshots/3_empty_last_line.txt +0 -7
- package/src/_tests/content_frame/snapshots/4_no_column.txt +0 -3
- package/src/_tests/content_frame/snapshots/5_line_1_and_2_digits.txt +0 -3
- package/src/_tests/content_frame/snapshots/6_line_too_long_column_undefined.txt +0 -3
- package/src/_tests/content_frame/snapshots/7_line_too_long_column_near_start.txt +0 -4
- package/src/_tests/content_frame/snapshots/8_line_too_long_column_near_middle.txt +0 -4
- package/src/_tests/content_frame/snapshots/9_line_too_long_column_near_end.txt +0 -4
- package/src/_tests/js_value/_inspect.test.html +0 -22
- package/src/_tests/js_value/array.test.js +0 -72
- package/src/_tests/js_value/biginit.test.js +0 -35
- package/src/_tests/js_value/boolean.test.js +0 -45
- package/src/_tests/js_value/date.test.js +0 -15
- package/src/_tests/js_value/error.test.js +0 -33
- package/src/_tests/js_value/function.test.js +0 -51
- package/src/_tests/js_value/instance.test.js +0 -12
- package/src/_tests/js_value/null.test.js +0 -6
- package/src/_tests/js_value/number.test.js +0 -182
- package/src/_tests/js_value/object.test.js +0 -173
- package/src/_tests/js_value/regexp.test.js +0 -15
- package/src/_tests/js_value/string.test.js +0 -106
- package/src/_tests/js_value/symbol.test.js +0 -20
- package/src/_tests/js_value/undefined.test.js +0 -6
- package/src/_tests/log/log_long.test_manual.mjs +0 -39
- package/src/_tests/log/log_modified.test_manual.mjs +0 -7
- package/src/_tests/log/logger.test.mjs +0 -90
- package/src/_tests/log/spinner.duration.test_manual.mjs +0 -25
- package/src/_tests/log/spinner.test.mjs +0 -33
- package/src/_tests/log/spinner.test_manual.mjs +0 -15
- package/src/_tests/percentage/percentage_distribution.test.mjs +0 -89
- package/src/_tests/time/decimals.test.js +0 -119
- package/src/_tests/time/duration.test.js +0 -20
- package/src/_tests/time/ellapsed.test.js +0 -10
- package/src/ansi/ansi_browser.js +0 -3
- package/src/ansi/ansi_node.js +0 -13
- package/src/ansi/ansi_runtime_agnostic.js +0 -107
- package/src/byte/byte.js +0 -44
- package/src/content_frame/content_frame.js +0 -157
- package/src/error/error_to_html.js +0 -22
- package/src/error/error_to_markdown.js +0 -14
- package/src/js_value/array.js +0 -58
- package/src/js_value/bigint.js +0 -3
- package/src/js_value/bigint_object.js +0 -5
- package/src/js_value/boolean.js +0 -1
- package/src/js_value/boolean_object.js +0 -12
- package/src/js_value/constructor.js +0 -10
- package/src/js_value/date.js +0 -8
- package/src/js_value/error.js +0 -34
- package/src/js_value/function.js +0 -20
- package/src/js_value/humanize.js +0 -142
- package/src/js_value/null.js +0 -1
- package/src/js_value/number.js +0 -101
- package/src/js_value/number_object.js +0 -9
- package/src/js_value/object.js +0 -78
- package/src/js_value/regexp.js +0 -1
- package/src/js_value/string.js +0 -141
- package/src/js_value/string_object.js +0 -10
- package/src/js_value/symbol.js +0 -24
- package/src/js_value/undefined.js +0 -1
- package/src/log/LOG_LEVELS.js +0 -9
- package/src/log/call_orderer.js +0 -39
- package/src/log/detailed_message.js +0 -29
- package/src/log/details.js +0 -26
- package/src/log/dynamic_log.js +0 -186
- package/src/log/logger.js +0 -85
- package/src/log/section.js +0 -50
- package/src/log/spinner.js +0 -72
- package/src/log/task_log.js +0 -49
- package/src/main_browser.js +0 -13
- package/src/main_node.js +0 -24
- package/src/percentage/distribute_percentages.js +0 -53
- package/src/time/time.js +0 -151
- package/src/unicode/unicode_browser.js +0 -7
- package/src/unicode/unicode_node.js +0 -8
- package/src/unicode/unicode_runtime_agnostic.js +0 -56
- package/src/utils/decimals.js +0 -95
- package/src/utils/indentation.js +0 -38
|
@@ -1,107 +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
|
-
const RED = "red";
|
|
6
|
-
const GREEN = "green";
|
|
7
|
-
const YELLOW = "yellow";
|
|
8
|
-
const BLUE = "blue";
|
|
9
|
-
const MAGENTA = "magenta";
|
|
10
|
-
const CYAN = "cyan";
|
|
11
|
-
const GREY = "grey";
|
|
12
|
-
const WHITE = "white";
|
|
13
|
-
const BLACK = "black";
|
|
14
|
-
|
|
15
|
-
const TEXT_COLOR_ANSI_CODES = {
|
|
16
|
-
[RED]: "\x1b[31m",
|
|
17
|
-
[GREEN]: "\x1b[32m",
|
|
18
|
-
[YELLOW]: "\x1b[33m",
|
|
19
|
-
[BLUE]: "\x1b[34m",
|
|
20
|
-
[MAGENTA]: "\x1b[35m",
|
|
21
|
-
[CYAN]: "\x1b[36m",
|
|
22
|
-
[GREY]: "\x1b[90m",
|
|
23
|
-
[WHITE]: "\x1b[37m",
|
|
24
|
-
[BLACK]: "\x1b[30m",
|
|
25
|
-
};
|
|
26
|
-
const BACKGROUND_COLOR_ANSI_CODES = {
|
|
27
|
-
[RED]: "\x1b[41m",
|
|
28
|
-
[GREEN]: "\x1b[42m",
|
|
29
|
-
[YELLOW]: "\x1b[43m",
|
|
30
|
-
[BLUE]: "\x1b[44m",
|
|
31
|
-
[MAGENTA]: "\x1b[45m",
|
|
32
|
-
[CYAN]: "\x1b[46m",
|
|
33
|
-
[GREY]: "\x1b[100m",
|
|
34
|
-
[WHITE]: "\x1b[47m",
|
|
35
|
-
[BLACK]: "\x1b[40m",
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const createAnsi = ({ supported }) => {
|
|
39
|
-
const ANSI = {
|
|
40
|
-
supported,
|
|
41
|
-
|
|
42
|
-
RED,
|
|
43
|
-
GREEN,
|
|
44
|
-
YELLOW,
|
|
45
|
-
BLUE,
|
|
46
|
-
MAGENTA,
|
|
47
|
-
CYAN,
|
|
48
|
-
GREY,
|
|
49
|
-
WHITE,
|
|
50
|
-
BLACK,
|
|
51
|
-
color: (text, color) => {
|
|
52
|
-
if (!ANSI.supported) {
|
|
53
|
-
return text;
|
|
54
|
-
}
|
|
55
|
-
if (!color) {
|
|
56
|
-
return text;
|
|
57
|
-
}
|
|
58
|
-
if (typeof text === "string" && text.trim() === "") {
|
|
59
|
-
// cannot set color of blank chars
|
|
60
|
-
return text;
|
|
61
|
-
}
|
|
62
|
-
const ansiEscapeCodeForTextColor = TEXT_COLOR_ANSI_CODES[color];
|
|
63
|
-
if (!ansiEscapeCodeForTextColor) {
|
|
64
|
-
return text;
|
|
65
|
-
}
|
|
66
|
-
return `${ansiEscapeCodeForTextColor}${text}${RESET}`;
|
|
67
|
-
},
|
|
68
|
-
backgroundColor: (text, color) => {
|
|
69
|
-
if (!ANSI.supported) {
|
|
70
|
-
return text;
|
|
71
|
-
}
|
|
72
|
-
if (!color) {
|
|
73
|
-
return text;
|
|
74
|
-
}
|
|
75
|
-
if (typeof text === "string" && text.trim() === "") {
|
|
76
|
-
// cannot set background color of blank chars
|
|
77
|
-
return text;
|
|
78
|
-
}
|
|
79
|
-
const ansiEscapeCodeForBackgroundColor =
|
|
80
|
-
BACKGROUND_COLOR_ANSI_CODES[color];
|
|
81
|
-
if (!ansiEscapeCodeForBackgroundColor) {
|
|
82
|
-
return text;
|
|
83
|
-
}
|
|
84
|
-
return `${ansiEscapeCodeForBackgroundColor}${text}${RESET}`;
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
BOLD: "\x1b[1m",
|
|
88
|
-
UNDERLINE: "\x1b[4m",
|
|
89
|
-
STRIKE: "\x1b[9m",
|
|
90
|
-
effect: (text, effect) => {
|
|
91
|
-
if (!ANSI.supported) {
|
|
92
|
-
return text;
|
|
93
|
-
}
|
|
94
|
-
if (!effect) {
|
|
95
|
-
return text;
|
|
96
|
-
}
|
|
97
|
-
// cannot add effect to empty string
|
|
98
|
-
if (text === "") {
|
|
99
|
-
return text;
|
|
100
|
-
}
|
|
101
|
-
const ansiEscapeCodeForEffect = effect;
|
|
102
|
-
return `${ansiEscapeCodeForEffect}${text}${RESET}`;
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
return ANSI;
|
|
107
|
-
};
|
package/src/byte/byte.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { setRoundedPrecision } from "../utils/decimals.js";
|
|
2
|
-
|
|
3
|
-
export const humanizeFileSize = (numberOfBytes, { decimals, short } = {}) => {
|
|
4
|
-
return inspectBytes(numberOfBytes, { decimals, short });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const humanizeMemory = (metricValue, { decimals, short } = {}) => {
|
|
8
|
-
return inspectBytes(metricValue, { decimals, fixedDecimals: true, short });
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const inspectBytes = (
|
|
12
|
-
number,
|
|
13
|
-
{ fixedDecimals = false, decimals, short } = {},
|
|
14
|
-
) => {
|
|
15
|
-
if (number === 0) {
|
|
16
|
-
return `0 B`;
|
|
17
|
-
}
|
|
18
|
-
const exponent = Math.min(
|
|
19
|
-
Math.floor(Math.log10(number) / 3),
|
|
20
|
-
BYTE_UNITS.length - 1,
|
|
21
|
-
);
|
|
22
|
-
const unitNumber = number / Math.pow(1000, exponent);
|
|
23
|
-
const unitName = BYTE_UNITS[exponent];
|
|
24
|
-
if (decimals === undefined) {
|
|
25
|
-
if (unitNumber < 100) {
|
|
26
|
-
decimals = 1;
|
|
27
|
-
} else {
|
|
28
|
-
decimals = 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const unitNumberRounded = setRoundedPrecision(unitNumber, {
|
|
32
|
-
decimals,
|
|
33
|
-
decimalsWhenSmall: 1,
|
|
34
|
-
});
|
|
35
|
-
const value = fixedDecimals
|
|
36
|
-
? unitNumberRounded.toFixed(decimals)
|
|
37
|
-
: unitNumberRounded;
|
|
38
|
-
if (short) {
|
|
39
|
-
return `${value}${unitName}`;
|
|
40
|
-
}
|
|
41
|
-
return `${value} ${unitName}`;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const BYTE_UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
const formatDefault = (v) => v;
|
|
2
|
-
|
|
3
|
-
export const generateContentFrame = ({
|
|
4
|
-
content,
|
|
5
|
-
line,
|
|
6
|
-
column,
|
|
7
|
-
|
|
8
|
-
linesAbove = 3,
|
|
9
|
-
linesBelow = 0,
|
|
10
|
-
lineMaxWidth = 120,
|
|
11
|
-
lineNumbersOnTheLeft = true,
|
|
12
|
-
lineMarker = true,
|
|
13
|
-
columnMarker = true,
|
|
14
|
-
format = formatDefault,
|
|
15
|
-
} = {}) => {
|
|
16
|
-
const lineStrings = content.split(/\r?\n/);
|
|
17
|
-
if (line === 0) line = 1;
|
|
18
|
-
if (column === undefined) {
|
|
19
|
-
columnMarker = false;
|
|
20
|
-
column = 1;
|
|
21
|
-
}
|
|
22
|
-
if (column === 0) column = 1;
|
|
23
|
-
|
|
24
|
-
let lineStartIndex = line - 1 - linesAbove;
|
|
25
|
-
if (lineStartIndex < 0) {
|
|
26
|
-
lineStartIndex = 0;
|
|
27
|
-
}
|
|
28
|
-
let lineEndIndex = line - 1 + linesBelow;
|
|
29
|
-
if (lineEndIndex > lineStrings.length - 1) {
|
|
30
|
-
lineEndIndex = lineStrings.length - 1;
|
|
31
|
-
}
|
|
32
|
-
if (columnMarker) {
|
|
33
|
-
// human reader deduce the line when there is a column marker
|
|
34
|
-
lineMarker = false;
|
|
35
|
-
}
|
|
36
|
-
if (line - 1 === lineEndIndex) {
|
|
37
|
-
lineMarker = false; // useless because last line
|
|
38
|
-
}
|
|
39
|
-
let lineIndex = lineStartIndex;
|
|
40
|
-
|
|
41
|
-
let columnsBefore;
|
|
42
|
-
let columnsAfter;
|
|
43
|
-
if (column > lineMaxWidth) {
|
|
44
|
-
columnsBefore = column - Math.ceil(lineMaxWidth / 2);
|
|
45
|
-
columnsAfter = column + Math.floor(lineMaxWidth / 2);
|
|
46
|
-
} else {
|
|
47
|
-
columnsBefore = 0;
|
|
48
|
-
columnsAfter = lineMaxWidth;
|
|
49
|
-
}
|
|
50
|
-
let columnMarkerIndex = column - 1 - columnsBefore;
|
|
51
|
-
|
|
52
|
-
let source = "";
|
|
53
|
-
while (lineIndex <= lineEndIndex) {
|
|
54
|
-
const lineString = lineStrings[lineIndex];
|
|
55
|
-
const lineNumber = lineIndex + 1;
|
|
56
|
-
const isLastLine = lineIndex === lineEndIndex;
|
|
57
|
-
const isMainLine = lineNumber === line;
|
|
58
|
-
lineIndex++;
|
|
59
|
-
|
|
60
|
-
write_aside: {
|
|
61
|
-
if (lineMarker) {
|
|
62
|
-
if (isMainLine) {
|
|
63
|
-
source += `${format(">", "marker_line")} `;
|
|
64
|
-
} else {
|
|
65
|
-
source += " ";
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (lineNumbersOnTheLeft) {
|
|
69
|
-
// fill with spaces to ensure if line moves from 7,8,9 to 10 the display is still great
|
|
70
|
-
const asideSource = `${fillLeft(lineNumber, lineEndIndex + 1)} |`;
|
|
71
|
-
source += `${format(asideSource, "line_number_aside")} `;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
write_line: {
|
|
75
|
-
source += truncateLine(lineString, {
|
|
76
|
-
start: columnsBefore,
|
|
77
|
-
end: columnsAfter,
|
|
78
|
-
prefix: "…",
|
|
79
|
-
suffix: "…",
|
|
80
|
-
format,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
write_column_marker: {
|
|
84
|
-
if (columnMarker && isMainLine) {
|
|
85
|
-
source += `\n`;
|
|
86
|
-
if (lineMarker) {
|
|
87
|
-
source += " ";
|
|
88
|
-
}
|
|
89
|
-
if (lineNumbersOnTheLeft) {
|
|
90
|
-
const asideSpaces = `${fillLeft(lineNumber, lineEndIndex + 1)} | `
|
|
91
|
-
.length;
|
|
92
|
-
source += " ".repeat(asideSpaces);
|
|
93
|
-
}
|
|
94
|
-
source += " ".repeat(columnMarkerIndex);
|
|
95
|
-
source += format("^", "marker_column");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (!isLastLine) {
|
|
99
|
-
source += "\n";
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return source;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const truncateLine = (line, { start, end, prefix, suffix, format }) => {
|
|
106
|
-
const lastIndex = line.length;
|
|
107
|
-
|
|
108
|
-
if (line.length === 0) {
|
|
109
|
-
// don't show any ellipsis if the line is empty
|
|
110
|
-
// because it's not truncated in that case
|
|
111
|
-
return "";
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const startTruncated = start > 0;
|
|
115
|
-
const endTruncated = lastIndex > end;
|
|
116
|
-
|
|
117
|
-
let from = startTruncated ? start + prefix.length : start;
|
|
118
|
-
let to = endTruncated ? end - suffix.length : end;
|
|
119
|
-
if (to > lastIndex) to = lastIndex;
|
|
120
|
-
|
|
121
|
-
if (start >= lastIndex || from === to) {
|
|
122
|
-
return "";
|
|
123
|
-
}
|
|
124
|
-
let result = "";
|
|
125
|
-
while (from < to) {
|
|
126
|
-
result += format(line[from], "char");
|
|
127
|
-
from++;
|
|
128
|
-
}
|
|
129
|
-
if (result.length === 0) {
|
|
130
|
-
return "";
|
|
131
|
-
}
|
|
132
|
-
if (startTruncated && endTruncated) {
|
|
133
|
-
return `${format(prefix, "marker_overflow_left")}${result}${format(
|
|
134
|
-
suffix,
|
|
135
|
-
"marker_overflow_right",
|
|
136
|
-
)}`;
|
|
137
|
-
}
|
|
138
|
-
if (startTruncated) {
|
|
139
|
-
return `${format(prefix, "marker_overflow_left")}${result}`;
|
|
140
|
-
}
|
|
141
|
-
if (endTruncated) {
|
|
142
|
-
return `${result}${format(suffix, "marker_overflow_right")}`;
|
|
143
|
-
}
|
|
144
|
-
return result;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const fillLeft = (value, biggestValue, char = " ") => {
|
|
148
|
-
const width = String(value).length;
|
|
149
|
-
const biggestWidth = String(biggestValue).length;
|
|
150
|
-
let missingWidth = biggestWidth - width;
|
|
151
|
-
let padded = "";
|
|
152
|
-
while (missingWidth--) {
|
|
153
|
-
padded += char;
|
|
154
|
-
}
|
|
155
|
-
padded += value;
|
|
156
|
-
return padded;
|
|
157
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const errorToHTML = (error) => {
|
|
2
|
-
const errorIsAPrimitive =
|
|
3
|
-
error === null ||
|
|
4
|
-
(typeof error !== "object" && typeof error !== "function");
|
|
5
|
-
|
|
6
|
-
if (errorIsAPrimitive) {
|
|
7
|
-
if (typeof error === "string") {
|
|
8
|
-
return `<pre>${escapeHtml(error)}</pre>`;
|
|
9
|
-
}
|
|
10
|
-
return `<pre>${JSON.stringify(error, null, " ")}</pre>`;
|
|
11
|
-
}
|
|
12
|
-
return `<pre>${escapeHtml(error.stack)}</pre>`;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const escapeHtml = (string) => {
|
|
16
|
-
return string
|
|
17
|
-
.replace(/&/g, "&")
|
|
18
|
-
.replace(/</g, "<")
|
|
19
|
-
.replace(/>/g, ">")
|
|
20
|
-
.replace(/"/g, """)
|
|
21
|
-
.replace(/'/g, "'");
|
|
22
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const errorToMarkdown = (error) => {
|
|
2
|
-
const errorIsAPrimitive =
|
|
3
|
-
error === null ||
|
|
4
|
-
(typeof error !== "object" && typeof error !== "function");
|
|
5
|
-
|
|
6
|
-
if (errorIsAPrimitive) {
|
|
7
|
-
return `\`\`\`js
|
|
8
|
-
${error}
|
|
9
|
-
\`\`\``;
|
|
10
|
-
}
|
|
11
|
-
return `\`\`\`
|
|
12
|
-
${error.stack}
|
|
13
|
-
\`\`\``;
|
|
14
|
-
};
|
package/src/js_value/array.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
preNewLineAndIndentation,
|
|
3
|
-
wrapNewLineAndIndentation,
|
|
4
|
-
} from "../utils/indentation.js";
|
|
5
|
-
import { inspectConstructor } from "./constructor.js";
|
|
6
|
-
|
|
7
|
-
export const inspectArray = (
|
|
8
|
-
value,
|
|
9
|
-
{
|
|
10
|
-
seen = [],
|
|
11
|
-
nestedHumanize,
|
|
12
|
-
depth,
|
|
13
|
-
indentUsingTab,
|
|
14
|
-
indentSize,
|
|
15
|
-
parenthesis,
|
|
16
|
-
useNew,
|
|
17
|
-
},
|
|
18
|
-
) => {
|
|
19
|
-
if (seen.indexOf(value) > -1) {
|
|
20
|
-
return "Symbol.for('circular')";
|
|
21
|
-
}
|
|
22
|
-
seen.push(value);
|
|
23
|
-
|
|
24
|
-
let valuesSource = "";
|
|
25
|
-
let i = 0;
|
|
26
|
-
const j = value.length;
|
|
27
|
-
|
|
28
|
-
while (i < j) {
|
|
29
|
-
const valueSource = value.hasOwnProperty(i)
|
|
30
|
-
? nestedHumanize(value[i], { seen })
|
|
31
|
-
: "";
|
|
32
|
-
if (i === 0) {
|
|
33
|
-
valuesSource += valueSource;
|
|
34
|
-
} else {
|
|
35
|
-
valuesSource += `,${preNewLineAndIndentation(valueSource, {
|
|
36
|
-
depth,
|
|
37
|
-
indentUsingTab,
|
|
38
|
-
indentSize,
|
|
39
|
-
})}`;
|
|
40
|
-
}
|
|
41
|
-
i++;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let arraySource;
|
|
45
|
-
if (valuesSource.length) {
|
|
46
|
-
arraySource = wrapNewLineAndIndentation(valuesSource, {
|
|
47
|
-
depth,
|
|
48
|
-
indentUsingTab,
|
|
49
|
-
indentSize,
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
arraySource = "";
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
arraySource = `[${arraySource}]`;
|
|
56
|
-
|
|
57
|
-
return inspectConstructor(arraySource, { parenthesis, useNew });
|
|
58
|
-
};
|
package/src/js_value/bigint.js
DELETED
package/src/js_value/boolean.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const inspectBoolean = (value) => value.toString();
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { inspectConstructor } from "./constructor.js";
|
|
2
|
-
|
|
3
|
-
export const inspectBooleanObject = (
|
|
4
|
-
value,
|
|
5
|
-
{ nestedHumanize, useNew, parenthesis },
|
|
6
|
-
) => {
|
|
7
|
-
const booleanSource = nestedHumanize(value.valueOf());
|
|
8
|
-
return inspectConstructor(`Boolean(${booleanSource})`, {
|
|
9
|
-
useNew,
|
|
10
|
-
parenthesis,
|
|
11
|
-
});
|
|
12
|
-
};
|
package/src/js_value/date.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { inspectConstructor } from "./constructor.js";
|
|
2
|
-
|
|
3
|
-
export const inspectDate = (value, { nestedHumanize, useNew, parenthesis }) => {
|
|
4
|
-
const dateSource = nestedHumanize(value.valueOf(), {
|
|
5
|
-
numericSeparator: false,
|
|
6
|
-
});
|
|
7
|
-
return inspectConstructor(`Date(${dateSource})`, { useNew, parenthesis });
|
|
8
|
-
};
|
package/src/js_value/error.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { inspectConstructor } from "./constructor.js";
|
|
2
|
-
|
|
3
|
-
export const inspectError = (
|
|
4
|
-
error,
|
|
5
|
-
{ nestedHumanize, useNew, parenthesis },
|
|
6
|
-
) => {
|
|
7
|
-
const messageSource = nestedHumanize(error.message);
|
|
8
|
-
|
|
9
|
-
const errorSource = inspectConstructor(
|
|
10
|
-
`${errorToConstructorName(error)}(${messageSource})`,
|
|
11
|
-
{
|
|
12
|
-
useNew,
|
|
13
|
-
parenthesis,
|
|
14
|
-
},
|
|
15
|
-
);
|
|
16
|
-
return errorSource;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const errorToConstructorName = ({ name }) => {
|
|
20
|
-
if (derivedErrorNameArray.includes(name)) {
|
|
21
|
-
return name;
|
|
22
|
-
}
|
|
23
|
-
return "Error";
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
27
|
-
const derivedErrorNameArray = [
|
|
28
|
-
"EvalError",
|
|
29
|
-
"RangeError",
|
|
30
|
-
"ReferenceError",
|
|
31
|
-
"SyntaxError",
|
|
32
|
-
"TypeError",
|
|
33
|
-
"URIError",
|
|
34
|
-
];
|
package/src/js_value/function.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export const inspectFunction = (
|
|
2
|
-
value,
|
|
3
|
-
{ showFunctionBody, parenthesis, depth },
|
|
4
|
-
) => {
|
|
5
|
-
let functionSource;
|
|
6
|
-
if (showFunctionBody) {
|
|
7
|
-
functionSource = value.toString();
|
|
8
|
-
} else {
|
|
9
|
-
const isArrowFunction = value.prototype === undefined;
|
|
10
|
-
const head = isArrowFunction
|
|
11
|
-
? "() =>"
|
|
12
|
-
: `function ${depth === 0 ? value.name : ""}()`;
|
|
13
|
-
functionSource = `${head} {/* hidden */}`;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (parenthesis) {
|
|
17
|
-
return `(${functionSource})`;
|
|
18
|
-
}
|
|
19
|
-
return functionSource;
|
|
20
|
-
};
|
package/src/js_value/humanize.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// tslint:disable:ordered-imports
|
|
2
|
-
|
|
3
|
-
// primitives
|
|
4
|
-
import { inspectBoolean } from "./boolean.js";
|
|
5
|
-
import { inspectNull } from "./null.js";
|
|
6
|
-
import { inspectNumber } from "./number.js";
|
|
7
|
-
import { inspectString } from "./string.js";
|
|
8
|
-
import { inspectSymbol } from "./symbol.js";
|
|
9
|
-
import { inspectUndefined } from "./undefined.js";
|
|
10
|
-
import { inspectBigInt } from "./bigint.js";
|
|
11
|
-
import { inspectArray } from "./array.js";
|
|
12
|
-
// composites
|
|
13
|
-
import { inspectBigIntObject } from "./bigint_object.js";
|
|
14
|
-
import { inspectBooleanObject } from "./boolean_object.js";
|
|
15
|
-
import { inspectError } from "./error.js";
|
|
16
|
-
import { inspectDate } from "./date.js";
|
|
17
|
-
import { inspectFunction } from "./function.js";
|
|
18
|
-
import { inspectNumberObject } from "./number_object.js";
|
|
19
|
-
import { inspectObject } from "./object.js";
|
|
20
|
-
import { inspectRegExp } from "./regexp.js";
|
|
21
|
-
import { inspectStringObject } from "./string_object.js";
|
|
22
|
-
import { inspectConstructor } from "./constructor.js";
|
|
23
|
-
|
|
24
|
-
export const humanize = (
|
|
25
|
-
value,
|
|
26
|
-
{
|
|
27
|
-
parenthesis = false,
|
|
28
|
-
quote = "auto",
|
|
29
|
-
canUseTemplateString = true,
|
|
30
|
-
useNew = false,
|
|
31
|
-
objectConstructor = false,
|
|
32
|
-
showFunctionBody = false,
|
|
33
|
-
indentUsingTab = false,
|
|
34
|
-
indentSize = 2,
|
|
35
|
-
numericSeparator = true,
|
|
36
|
-
preserveLineBreaks = false,
|
|
37
|
-
} = {},
|
|
38
|
-
) => {
|
|
39
|
-
const scopedHumanize = (scopedValue, scopedOptions) => {
|
|
40
|
-
const options = {
|
|
41
|
-
...scopedOptions,
|
|
42
|
-
nestedHumanize: (nestedValue, nestedOptions = {}) => {
|
|
43
|
-
return scopedHumanize(nestedValue, {
|
|
44
|
-
...scopedOptions,
|
|
45
|
-
depth: scopedOptions.depth + 1,
|
|
46
|
-
...nestedOptions,
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
return humanizeValue(scopedValue, options);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return scopedHumanize(value, {
|
|
54
|
-
parenthesis,
|
|
55
|
-
quote,
|
|
56
|
-
canUseTemplateString,
|
|
57
|
-
useNew,
|
|
58
|
-
objectConstructor,
|
|
59
|
-
showFunctionBody,
|
|
60
|
-
indentUsingTab,
|
|
61
|
-
indentSize,
|
|
62
|
-
numericSeparator,
|
|
63
|
-
preserveLineBreaks,
|
|
64
|
-
depth: 0,
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const humanizeMethodSymbol = Symbol.for("inspect");
|
|
69
|
-
|
|
70
|
-
const humanizeValue = (value, options) => {
|
|
71
|
-
const customHumanize = value && value[humanizeMethodSymbol];
|
|
72
|
-
if (customHumanize) {
|
|
73
|
-
return customHumanize(options);
|
|
74
|
-
}
|
|
75
|
-
const primitiveType = primitiveTypeFromValue(value);
|
|
76
|
-
const primitiveStringifier = primitiveStringifiers[primitiveType];
|
|
77
|
-
if (primitiveStringifier) {
|
|
78
|
-
return primitiveStringifier(value, options);
|
|
79
|
-
}
|
|
80
|
-
const compositeType = compositeTypeFromObject(value);
|
|
81
|
-
const compositeStringifier = compositeStringifiers[compositeType];
|
|
82
|
-
if (compositeStringifier) {
|
|
83
|
-
return compositeStringifier(value, options);
|
|
84
|
-
}
|
|
85
|
-
return inspectConstructor(
|
|
86
|
-
`${compositeType}(${inspectObject(value, options)})`,
|
|
87
|
-
{
|
|
88
|
-
...options,
|
|
89
|
-
parenthesis: false,
|
|
90
|
-
},
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const primitiveTypeFromValue = (value) => {
|
|
95
|
-
if (value === null) {
|
|
96
|
-
return "null";
|
|
97
|
-
}
|
|
98
|
-
if (value === undefined) {
|
|
99
|
-
return "undefined";
|
|
100
|
-
}
|
|
101
|
-
return typeof value;
|
|
102
|
-
};
|
|
103
|
-
const primitiveStringifiers = {
|
|
104
|
-
boolean: inspectBoolean,
|
|
105
|
-
function: inspectFunction,
|
|
106
|
-
null: inspectNull,
|
|
107
|
-
number: inspectNumber,
|
|
108
|
-
string: inspectString,
|
|
109
|
-
symbol: inspectSymbol,
|
|
110
|
-
undefined: inspectUndefined,
|
|
111
|
-
bigint: inspectBigInt,
|
|
112
|
-
};
|
|
113
|
-
const compositeTypeFromObject = (object) => {
|
|
114
|
-
if (typeof object === "object" && Object.getPrototypeOf(object) === null) {
|
|
115
|
-
return "Object";
|
|
116
|
-
}
|
|
117
|
-
const toStringResult = toString.call(object);
|
|
118
|
-
// returns format is '[object ${tagName}]';
|
|
119
|
-
// and we want ${tagName}
|
|
120
|
-
const tagName = toStringResult.slice("[object ".length, -1);
|
|
121
|
-
if (tagName === "Object") {
|
|
122
|
-
const objectConstructorName = object.constructor.name;
|
|
123
|
-
if (objectConstructorName !== "Object") {
|
|
124
|
-
return objectConstructorName;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return tagName;
|
|
128
|
-
};
|
|
129
|
-
const { toString } = Object.prototype;
|
|
130
|
-
|
|
131
|
-
const compositeStringifiers = {
|
|
132
|
-
Array: inspectArray,
|
|
133
|
-
BigInt: inspectBigIntObject,
|
|
134
|
-
Boolean: inspectBooleanObject,
|
|
135
|
-
Error: inspectError,
|
|
136
|
-
Date: inspectDate,
|
|
137
|
-
Function: inspectFunction,
|
|
138
|
-
Number: inspectNumberObject,
|
|
139
|
-
Object: inspectObject,
|
|
140
|
-
RegExp: inspectRegExp,
|
|
141
|
-
String: inspectStringObject,
|
|
142
|
-
};
|
package/src/js_value/null.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const inspectNull = () => "null";
|