@jsenv/humanize 1.6.0 → 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 +36 -37
- 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 +18 -19
- 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 -155
- 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/error/format_error.js +0 -53
- 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 -25
- 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
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";
|
package/src/js_value/number.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/numeric-separators-style.js
|
|
2
|
-
|
|
3
|
-
export const inspectNumber = (value, { numericSeparator }) => {
|
|
4
|
-
if (isNegativeZero(value)) {
|
|
5
|
-
return "-0";
|
|
6
|
-
}
|
|
7
|
-
// isNaN
|
|
8
|
-
// eslint-disable-next-line no-self-compare
|
|
9
|
-
if (value !== value) {
|
|
10
|
-
return "NaN";
|
|
11
|
-
}
|
|
12
|
-
if (value === Infinity) {
|
|
13
|
-
return "Infinity";
|
|
14
|
-
}
|
|
15
|
-
if (value === -Infinity) {
|
|
16
|
-
return "-Infinity";
|
|
17
|
-
}
|
|
18
|
-
const numberString = String(value);
|
|
19
|
-
if (!numericSeparator) {
|
|
20
|
-
return numberString;
|
|
21
|
-
}
|
|
22
|
-
const {
|
|
23
|
-
number,
|
|
24
|
-
mark = "",
|
|
25
|
-
sign = "",
|
|
26
|
-
power = "",
|
|
27
|
-
} = numberString.match(
|
|
28
|
-
/^(?<number>.*?)(?:(?<mark>e)(?<sign>[+-])?(?<power>\d+))?$/i,
|
|
29
|
-
).groups;
|
|
30
|
-
const numberWithSeparators = formatNumber(number);
|
|
31
|
-
const powerWithSeparators = addSeparator(power, {
|
|
32
|
-
minimumDigits: 5,
|
|
33
|
-
groupLength: 3,
|
|
34
|
-
});
|
|
35
|
-
return `${numberWithSeparators}${mark}${sign}${powerWithSeparators}`;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Use this and instead of Object.is(value, -0)
|
|
39
|
-
// because in some corner cases firefox returns false
|
|
40
|
-
// for Object.is(-0, -0)
|
|
41
|
-
const isNegativeZero = (value) => {
|
|
42
|
-
return value === 0 && 1 / value === -Infinity;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const formatNumber = (numberString) => {
|
|
46
|
-
const parts = numberString.split(".");
|
|
47
|
-
const [integer, fractional] = parts;
|
|
48
|
-
|
|
49
|
-
if (parts.length === 2) {
|
|
50
|
-
const integerWithSeparators = addSeparator(integer, {
|
|
51
|
-
minimumDigits: 5,
|
|
52
|
-
groupLength: 3,
|
|
53
|
-
});
|
|
54
|
-
return `${integerWithSeparators}.${fractional}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return addSeparator(integer, {
|
|
58
|
-
minimumDigits: 5,
|
|
59
|
-
groupLength: 3,
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const addSeparator = (numberString, { minimumDigits, groupLength }) => {
|
|
64
|
-
if (numberString[0] === "-") {
|
|
65
|
-
return `-${groupDigits(numberString.slice(1), {
|
|
66
|
-
minimumDigits,
|
|
67
|
-
groupLength,
|
|
68
|
-
})}`;
|
|
69
|
-
}
|
|
70
|
-
return groupDigits(numberString, { minimumDigits, groupLength });
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const groupDigits = (digits, { minimumDigits, groupLength }) => {
|
|
74
|
-
const digitCount = digits.length;
|
|
75
|
-
if (digitCount < minimumDigits) {
|
|
76
|
-
return digits;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let digitsWithSeparator = digits.slice(-groupLength);
|
|
80
|
-
let remainingDigits = digits.slice(0, -groupLength);
|
|
81
|
-
while (remainingDigits.length) {
|
|
82
|
-
const group = remainingDigits.slice(-groupLength);
|
|
83
|
-
remainingDigits = remainingDigits.slice(0, -groupLength);
|
|
84
|
-
digitsWithSeparator = `${group}_${digitsWithSeparator}`;
|
|
85
|
-
}
|
|
86
|
-
return digitsWithSeparator;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// const addSeparatorFromLeft = (value, { minimumDigits, groupLength }) => {
|
|
90
|
-
// const { length } = value;
|
|
91
|
-
// if (length < minimumDigits) {
|
|
92
|
-
// return value;
|
|
93
|
-
// }
|
|
94
|
-
|
|
95
|
-
// const parts = [];
|
|
96
|
-
// for (let start = 0; start < length; start += groupLength) {
|
|
97
|
-
// const end = Math.min(start + groupLength, length);
|
|
98
|
-
// parts.push(value.slice(start, end));
|
|
99
|
-
// }
|
|
100
|
-
// return parts.join("_");
|
|
101
|
-
// };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { inspectConstructor } from "./constructor.js";
|
|
2
|
-
|
|
3
|
-
export const inspectNumberObject = (
|
|
4
|
-
value,
|
|
5
|
-
{ nestedHumanize, useNew, parenthesis },
|
|
6
|
-
) => {
|
|
7
|
-
const numberSource = nestedHumanize(value.valueOf());
|
|
8
|
-
return inspectConstructor(`Number(${numberSource})`, { useNew, parenthesis });
|
|
9
|
-
};
|
package/src/js_value/object.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
preNewLineAndIndentation,
|
|
3
|
-
wrapNewLineAndIndentation,
|
|
4
|
-
} from "../utils/indentation.js";
|
|
5
|
-
import { inspectConstructor } from "./constructor.js";
|
|
6
|
-
|
|
7
|
-
export const inspectObject = (
|
|
8
|
-
value,
|
|
9
|
-
{
|
|
10
|
-
nestedHumanize,
|
|
11
|
-
seen = [],
|
|
12
|
-
depth,
|
|
13
|
-
indentUsingTab,
|
|
14
|
-
indentSize,
|
|
15
|
-
objectConstructor,
|
|
16
|
-
parenthesis,
|
|
17
|
-
useNew,
|
|
18
|
-
},
|
|
19
|
-
) => {
|
|
20
|
-
if (seen.indexOf(value) > -1) return "Symbol.for('circular')";
|
|
21
|
-
|
|
22
|
-
seen.push(value);
|
|
23
|
-
|
|
24
|
-
const propertySourceArray = [];
|
|
25
|
-
Object.getOwnPropertyNames(value).forEach((propertyName) => {
|
|
26
|
-
const propertyNameAsNumber = parseInt(propertyName, 10);
|
|
27
|
-
const propertyNameSource = nestedHumanize(
|
|
28
|
-
Number.isInteger(propertyNameAsNumber)
|
|
29
|
-
? propertyNameAsNumber
|
|
30
|
-
: propertyName,
|
|
31
|
-
);
|
|
32
|
-
propertySourceArray.push({
|
|
33
|
-
nameOrSymbolSource: propertyNameSource,
|
|
34
|
-
valueSource: nestedHumanize(value[propertyName], { seen }),
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
Object.getOwnPropertySymbols(value).forEach((symbol) => {
|
|
38
|
-
propertySourceArray.push({
|
|
39
|
-
nameOrSymbolSource: `[${nestedHumanize(symbol)}]`,
|
|
40
|
-
valueSource: nestedHumanize(value[symbol], { seen }),
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
let propertiesSource = "";
|
|
45
|
-
propertySourceArray.forEach(({ nameOrSymbolSource, valueSource }, index) => {
|
|
46
|
-
if (index === 0) {
|
|
47
|
-
propertiesSource += `${nameOrSymbolSource}: ${valueSource}`;
|
|
48
|
-
} else {
|
|
49
|
-
propertiesSource += `,${preNewLineAndIndentation(
|
|
50
|
-
`${nameOrSymbolSource}: ${valueSource}`,
|
|
51
|
-
{
|
|
52
|
-
depth,
|
|
53
|
-
indentUsingTab,
|
|
54
|
-
indentSize,
|
|
55
|
-
},
|
|
56
|
-
)}`;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
let objectSource;
|
|
61
|
-
if (propertiesSource.length) {
|
|
62
|
-
objectSource = `${wrapNewLineAndIndentation(propertiesSource, {
|
|
63
|
-
depth,
|
|
64
|
-
indentUsingTab,
|
|
65
|
-
indentSize,
|
|
66
|
-
})}`;
|
|
67
|
-
} else {
|
|
68
|
-
objectSource = "";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (objectConstructor) {
|
|
72
|
-
objectSource = `Object({${objectSource}})`;
|
|
73
|
-
} else {
|
|
74
|
-
objectSource = `{${objectSource}}`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return inspectConstructor(objectSource, { parenthesis, useNew });
|
|
78
|
-
};
|
package/src/js_value/regexp.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const inspectRegExp = (value) => value.toString();
|
package/src/js_value/string.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
const DOUBLE_QUOTE = `"`;
|
|
2
|
-
const SINGLE_QUOTE = `'`;
|
|
3
|
-
const BACKTICK = "`";
|
|
4
|
-
|
|
5
|
-
export const inspectString = (
|
|
6
|
-
value,
|
|
7
|
-
{
|
|
8
|
-
quote = "auto",
|
|
9
|
-
canUseTemplateString = false,
|
|
10
|
-
preserveLineBreaks = false,
|
|
11
|
-
quoteDefault = DOUBLE_QUOTE,
|
|
12
|
-
} = {},
|
|
13
|
-
) => {
|
|
14
|
-
quote =
|
|
15
|
-
quote === "auto"
|
|
16
|
-
? determineQuote(value, { canUseTemplateString, quoteDefault })
|
|
17
|
-
: quote;
|
|
18
|
-
if (quote === BACKTICK) {
|
|
19
|
-
return `\`${escapeTemplateStringSpecialCharacters(value)}\``;
|
|
20
|
-
}
|
|
21
|
-
return surroundStringWith(value, { quote, preserveLineBreaks });
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// https://github.com/mgenware/string-to-template-literal/blob/main/src/main.ts#L1
|
|
25
|
-
const escapeTemplateStringSpecialCharacters = (string) => {
|
|
26
|
-
string = String(string);
|
|
27
|
-
let i = 0;
|
|
28
|
-
let escapedString = "";
|
|
29
|
-
while (i < string.length) {
|
|
30
|
-
const char = string[i];
|
|
31
|
-
i++;
|
|
32
|
-
escapedString += isTemplateStringSpecialChar(char) ? `\\${char}` : char;
|
|
33
|
-
}
|
|
34
|
-
return escapedString;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const isTemplateStringSpecialChar = (char) =>
|
|
38
|
-
templateStringSpecialChars.indexOf(char) > -1;
|
|
39
|
-
const templateStringSpecialChars = ["\\", "`", "$"];
|
|
40
|
-
|
|
41
|
-
export const determineQuote = (
|
|
42
|
-
string,
|
|
43
|
-
{ canUseTemplateString, quoteDefault = DOUBLE_QUOTE } = {},
|
|
44
|
-
) => {
|
|
45
|
-
const containsDoubleQuote = string.includes(DOUBLE_QUOTE);
|
|
46
|
-
if (!containsDoubleQuote) {
|
|
47
|
-
return DOUBLE_QUOTE;
|
|
48
|
-
}
|
|
49
|
-
const containsSimpleQuote = string.includes(SINGLE_QUOTE);
|
|
50
|
-
if (!containsSimpleQuote) {
|
|
51
|
-
return SINGLE_QUOTE;
|
|
52
|
-
}
|
|
53
|
-
if (canUseTemplateString) {
|
|
54
|
-
const containsBackTick = string.includes(BACKTICK);
|
|
55
|
-
if (!containsBackTick) {
|
|
56
|
-
return BACKTICK;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const doubleQuoteCount = string.split(DOUBLE_QUOTE).length - 1;
|
|
60
|
-
const singleQuoteCount = string.split(SINGLE_QUOTE).length - 1;
|
|
61
|
-
if (singleQuoteCount > doubleQuoteCount) {
|
|
62
|
-
return DOUBLE_QUOTE;
|
|
63
|
-
}
|
|
64
|
-
if (doubleQuoteCount > singleQuoteCount) {
|
|
65
|
-
return SINGLE_QUOTE;
|
|
66
|
-
}
|
|
67
|
-
return quoteDefault;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const inspectChar = (char, { quote, preserveLineBreaks }) => {
|
|
71
|
-
const point = char.charCodeAt(0);
|
|
72
|
-
if (preserveLineBreaks && (char === "\n" || char === "\r")) {
|
|
73
|
-
return char;
|
|
74
|
-
}
|
|
75
|
-
if (
|
|
76
|
-
char === quote ||
|
|
77
|
-
point === 92 ||
|
|
78
|
-
point < 32 ||
|
|
79
|
-
(point > 126 && point < 160) ||
|
|
80
|
-
// line separators
|
|
81
|
-
point === 8232 ||
|
|
82
|
-
point === 8233
|
|
83
|
-
) {
|
|
84
|
-
const replacement =
|
|
85
|
-
char === quote
|
|
86
|
-
? `\\${quote}`
|
|
87
|
-
: point === 8232
|
|
88
|
-
? "\\u2028"
|
|
89
|
-
: point === 8233
|
|
90
|
-
? "\\u2029"
|
|
91
|
-
: meta[point];
|
|
92
|
-
return replacement;
|
|
93
|
-
}
|
|
94
|
-
return char;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// https://github.com/jsenv/jsenv-uneval/blob/6c97ef9d8f2e9425a66f2c88347e0a118d427f3a/src/internal/escapeString.js#L3
|
|
98
|
-
// https://github.com/jsenv/jsenv-inspect/blob/bb11de3adf262b68f71ed82b0a37d4528dd42229/src/internal/string.js#L3
|
|
99
|
-
// https://github.com/joliss/js-string-escape/blob/master/index.js
|
|
100
|
-
// http://javascript.crockford.com/remedial.html
|
|
101
|
-
const surroundStringWith = (string, { quote, preserveLineBreaks }) => {
|
|
102
|
-
let result = "";
|
|
103
|
-
let last = 0;
|
|
104
|
-
const lastIndex = string.length;
|
|
105
|
-
let i = 0;
|
|
106
|
-
while (i < lastIndex) {
|
|
107
|
-
const char = string[i];
|
|
108
|
-
const replacement = inspectChar(char, { quote, preserveLineBreaks });
|
|
109
|
-
if (char !== replacement) {
|
|
110
|
-
if (last === i) {
|
|
111
|
-
result += replacement;
|
|
112
|
-
} else {
|
|
113
|
-
result += `${string.slice(last, i)}${replacement}`;
|
|
114
|
-
}
|
|
115
|
-
last = i + 1;
|
|
116
|
-
}
|
|
117
|
-
i++;
|
|
118
|
-
}
|
|
119
|
-
if (last !== lastIndex) {
|
|
120
|
-
result += string.slice(last);
|
|
121
|
-
}
|
|
122
|
-
return `${quote}${result}${quote}`;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// prettier-ignore
|
|
126
|
-
const meta = [
|
|
127
|
-
'\\x00', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\x07', // x07
|
|
128
|
-
'\\b', '\\t', '\\n', '\\x0B', '\\f', '\\r', '\\x0E', '\\x0F', // x0F
|
|
129
|
-
'\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17', // x17
|
|
130
|
-
'\\x18', '\\x19', '\\x1A', '\\x1B', '\\x1C', '\\x1D', '\\x1E', '\\x1F', // x1F
|
|
131
|
-
'', '', '', '', '', '', '', "\\'", '', '', '', '', '', '', '', '', // x2F
|
|
132
|
-
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x3F
|
|
133
|
-
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x4F
|
|
134
|
-
'', '', '', '', '', '', '', '', '', '', '', '', '\\\\', '', '', '', // x5F
|
|
135
|
-
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x6F
|
|
136
|
-
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\\x7F', // x7F
|
|
137
|
-
'\\x80', '\\x81', '\\x82', '\\x83', '\\x84', '\\x85', '\\x86', '\\x87', // x87
|
|
138
|
-
'\\x88', '\\x89', '\\x8A', '\\x8B', '\\x8C', '\\x8D', '\\x8E', '\\x8F', // x8F
|
|
139
|
-
'\\x90', '\\x91', '\\x92', '\\x93', '\\x94', '\\x95', '\\x96', '\\x97', // x97
|
|
140
|
-
'\\x98', '\\x99', '\\x9A', '\\x9B', '\\x9C', '\\x9D', '\\x9E', '\\x9F', // x9F
|
|
141
|
-
];
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { inspectConstructor } from "./constructor.js";
|
|
2
|
-
|
|
3
|
-
export const inspectStringObject = (
|
|
4
|
-
value,
|
|
5
|
-
{ nestedHumanize, useNew, parenthesis },
|
|
6
|
-
) => {
|
|
7
|
-
const stringSource = nestedHumanize(value.valueOf());
|
|
8
|
-
|
|
9
|
-
return inspectConstructor(`String(${stringSource})`, { useNew, parenthesis });
|
|
10
|
-
};
|
package/src/js_value/symbol.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const inspectSymbol = (value, { nestedHumanize, parenthesis }) => {
|
|
2
|
-
const symbolDescription = symbolToDescription(value);
|
|
3
|
-
const symbolDescriptionSource = symbolDescription
|
|
4
|
-
? nestedHumanize(symbolDescription)
|
|
5
|
-
: "";
|
|
6
|
-
const symbolSource = `Symbol(${symbolDescriptionSource})`;
|
|
7
|
-
|
|
8
|
-
if (parenthesis) return `${symbolSource}`;
|
|
9
|
-
return symbolSource;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const symbolToDescription =
|
|
13
|
-
"description" in Symbol.prototype
|
|
14
|
-
? (symbol) => symbol.description
|
|
15
|
-
: (symbol) => {
|
|
16
|
-
const toStringResult = symbol.toString();
|
|
17
|
-
const openingParenthesisIndex = toStringResult.indexOf("(");
|
|
18
|
-
const closingParenthesisIndex = toStringResult.indexOf(")");
|
|
19
|
-
const symbolDescription = toStringResult.slice(
|
|
20
|
-
openingParenthesisIndex + 1,
|
|
21
|
-
closingParenthesisIndex,
|
|
22
|
-
);
|
|
23
|
-
return symbolDescription;
|
|
24
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const inspectUndefined = () => "undefined";
|
package/src/log/LOG_LEVELS.js
DELETED
package/src/log/call_orderer.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export const createCallOrderer = () => {
|
|
2
|
-
const queue = [];
|
|
3
|
-
const callWhenPreviousExecutionAreDone = (executionIndex, callback) => {
|
|
4
|
-
if (queue[executionIndex]) {
|
|
5
|
-
throw new Error(`${executionIndex} already used`);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
let allBeforeAreDone = true;
|
|
9
|
-
if (executionIndex > 0) {
|
|
10
|
-
let beforeIndex = executionIndex - 1;
|
|
11
|
-
do {
|
|
12
|
-
const value = queue[beforeIndex];
|
|
13
|
-
if (!value) {
|
|
14
|
-
allBeforeAreDone = false;
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
} while (beforeIndex--);
|
|
18
|
-
}
|
|
19
|
-
if (!allBeforeAreDone) {
|
|
20
|
-
queue[executionIndex] = callback;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
queue[executionIndex] = true;
|
|
24
|
-
callback();
|
|
25
|
-
let afterIndex = executionIndex + 1;
|
|
26
|
-
while (afterIndex < queue.length) {
|
|
27
|
-
const value = queue[afterIndex];
|
|
28
|
-
if (value === undefined) {
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === "function") {
|
|
32
|
-
queue[afterIndex] = true;
|
|
33
|
-
value();
|
|
34
|
-
}
|
|
35
|
-
afterIndex++;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return callWhenPreviousExecutionAreDone;
|
|
39
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export const createDetailedMessage = (message, details = {}) => {
|
|
2
|
-
let text = `${message}`;
|
|
3
|
-
const namedSectionsText = renderNamedSections(details);
|
|
4
|
-
if (namedSectionsText) {
|
|
5
|
-
text += `
|
|
6
|
-
${namedSectionsText}`;
|
|
7
|
-
}
|
|
8
|
-
return text;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const renderNamedSections = (namedSections) => {
|
|
12
|
-
let text = "";
|
|
13
|
-
let keys = Object.keys(namedSections);
|
|
14
|
-
for (const key of keys) {
|
|
15
|
-
const isLastKey = key === keys[keys.length - 1];
|
|
16
|
-
const value = namedSections[key];
|
|
17
|
-
text += `--- ${key} ---
|
|
18
|
-
${
|
|
19
|
-
Array.isArray(value)
|
|
20
|
-
? value.join(`
|
|
21
|
-
`)
|
|
22
|
-
: value
|
|
23
|
-
}`;
|
|
24
|
-
if (!isLastKey) {
|
|
25
|
-
text += "\n";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return text;
|
|
29
|
-
};
|
package/src/log/details.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ANSI } from "../ansi/ansi_node.js";
|
|
2
|
-
|
|
3
|
-
export const renderDetails = (data) => {
|
|
4
|
-
const details = [];
|
|
5
|
-
for (const key of Object.keys(data)) {
|
|
6
|
-
const value = data[key];
|
|
7
|
-
let valueString = "";
|
|
8
|
-
valueString += ANSI.color(`${key}:`, ANSI.GREY);
|
|
9
|
-
const useNonGreyAnsiColor =
|
|
10
|
-
typeof value === "string" && value.includes("\x1b");
|
|
11
|
-
valueString += " ";
|
|
12
|
-
valueString += useNonGreyAnsiColor
|
|
13
|
-
? value
|
|
14
|
-
: ANSI.color(String(value), ANSI.GREY);
|
|
15
|
-
details.push(valueString);
|
|
16
|
-
}
|
|
17
|
-
if (details.length === 0) {
|
|
18
|
-
return "";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let string = "";
|
|
22
|
-
string += ` ${ANSI.color("(", ANSI.GREY)}`;
|
|
23
|
-
string += details.join(ANSI.color(", ", ANSI.GREY));
|
|
24
|
-
string += ANSI.color(")", ANSI.GREY);
|
|
25
|
-
return string;
|
|
26
|
-
};
|