@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.
Files changed (90) hide show
  1. package/dist/browser/jsenv_humanize_browser.js +539 -482
  2. package/dist/browser/jsenv_humanize_browser.js.map +76 -0
  3. package/dist/node/jsenv_humanize_node.js +58 -7
  4. package/dist/node/jsenv_humanize_node.js.map +97 -0
  5. package/dist/node/jsenv_humanize_node_modules.js +23 -15
  6. package/dist/node/jsenv_humanize_node_modules.js.map +21 -0
  7. package/package.json +20 -17
  8. package/src/_tests/byte/file_size.test.js +0 -18
  9. package/src/_tests/byte/memory.test.js +0 -11
  10. package/src/_tests/content_frame/content_frame.test.js +0 -156
  11. package/src/_tests/content_frame/snapshots/10_line_and_column_are_zero.txt +0 -2
  12. package/src/_tests/content_frame/snapshots/11_line_is_last.txt +0 -3
  13. package/src/_tests/content_frame/snapshots/1_basic.txt +0 -4
  14. package/src/_tests/content_frame/snapshots/2_basic_2.txt +0 -6
  15. package/src/_tests/content_frame/snapshots/3_empty_last_line.txt +0 -7
  16. package/src/_tests/content_frame/snapshots/4_no_column.txt +0 -3
  17. package/src/_tests/content_frame/snapshots/5_line_1_and_2_digits.txt +0 -3
  18. package/src/_tests/content_frame/snapshots/6_line_too_long_column_undefined.txt +0 -3
  19. package/src/_tests/content_frame/snapshots/7_line_too_long_column_near_start.txt +0 -4
  20. package/src/_tests/content_frame/snapshots/8_line_too_long_column_near_middle.txt +0 -4
  21. package/src/_tests/content_frame/snapshots/9_line_too_long_column_near_end.txt +0 -4
  22. package/src/_tests/js_value/_inspect.test.html +0 -22
  23. package/src/_tests/js_value/array.test.js +0 -72
  24. package/src/_tests/js_value/biginit.test.js +0 -35
  25. package/src/_tests/js_value/boolean.test.js +0 -45
  26. package/src/_tests/js_value/date.test.js +0 -15
  27. package/src/_tests/js_value/error.test.js +0 -33
  28. package/src/_tests/js_value/function.test.js +0 -51
  29. package/src/_tests/js_value/instance.test.js +0 -12
  30. package/src/_tests/js_value/null.test.js +0 -6
  31. package/src/_tests/js_value/number.test.js +0 -182
  32. package/src/_tests/js_value/object.test.js +0 -173
  33. package/src/_tests/js_value/regexp.test.js +0 -15
  34. package/src/_tests/js_value/string.test.js +0 -106
  35. package/src/_tests/js_value/symbol.test.js +0 -20
  36. package/src/_tests/js_value/undefined.test.js +0 -6
  37. package/src/_tests/log/log_long.test_manual.mjs +0 -39
  38. package/src/_tests/log/log_modified.test_manual.mjs +0 -7
  39. package/src/_tests/log/logger.test.mjs +0 -90
  40. package/src/_tests/log/spinner.duration.test_manual.mjs +0 -25
  41. package/src/_tests/log/spinner.test.mjs +0 -33
  42. package/src/_tests/log/spinner.test_manual.mjs +0 -15
  43. package/src/_tests/percentage/percentage_distribution.test.mjs +0 -89
  44. package/src/_tests/time/decimals.test.js +0 -119
  45. package/src/_tests/time/duration.test.js +0 -20
  46. package/src/_tests/time/ellapsed.test.js +0 -10
  47. package/src/ansi/ansi_browser.js +0 -3
  48. package/src/ansi/ansi_node.js +0 -13
  49. package/src/ansi/ansi_runtime_agnostic.js +0 -107
  50. package/src/byte/byte.js +0 -44
  51. package/src/content_frame/content_frame.js +0 -157
  52. package/src/error/error_to_html.js +0 -22
  53. package/src/error/error_to_markdown.js +0 -14
  54. package/src/js_value/array.js +0 -58
  55. package/src/js_value/bigint.js +0 -3
  56. package/src/js_value/bigint_object.js +0 -5
  57. package/src/js_value/boolean.js +0 -1
  58. package/src/js_value/boolean_object.js +0 -12
  59. package/src/js_value/constructor.js +0 -10
  60. package/src/js_value/date.js +0 -8
  61. package/src/js_value/error.js +0 -34
  62. package/src/js_value/function.js +0 -20
  63. package/src/js_value/humanize.js +0 -142
  64. package/src/js_value/null.js +0 -1
  65. package/src/js_value/number.js +0 -101
  66. package/src/js_value/number_object.js +0 -9
  67. package/src/js_value/object.js +0 -78
  68. package/src/js_value/regexp.js +0 -1
  69. package/src/js_value/string.js +0 -141
  70. package/src/js_value/string_object.js +0 -10
  71. package/src/js_value/symbol.js +0 -24
  72. package/src/js_value/undefined.js +0 -1
  73. package/src/log/LOG_LEVELS.js +0 -9
  74. package/src/log/call_orderer.js +0 -39
  75. package/src/log/detailed_message.js +0 -29
  76. package/src/log/details.js +0 -26
  77. package/src/log/dynamic_log.js +0 -186
  78. package/src/log/logger.js +0 -85
  79. package/src/log/section.js +0 -50
  80. package/src/log/spinner.js +0 -72
  81. package/src/log/task_log.js +0 -49
  82. package/src/main_browser.js +0 -13
  83. package/src/main_node.js +0 -24
  84. package/src/percentage/distribute_percentages.js +0 -53
  85. package/src/time/time.js +0 -151
  86. package/src/unicode/unicode_browser.js +0 -7
  87. package/src/unicode/unicode_node.js +0 -8
  88. package/src/unicode/unicode_runtime_agnostic.js +0 -56
  89. package/src/utils/decimals.js +0 -95
  90. package/src/utils/indentation.js +0 -38
@@ -1,18 +1,26 @@
1
1
  const createDetailedMessage = (message, details = {}) => {
2
- let text = "".concat(message);
2
+ let text = `${message}`;
3
3
  const namedSectionsText = renderNamedSections(details);
4
4
  if (namedSectionsText) {
5
- text += "\n".concat(namedSectionsText);
5
+ text += `
6
+ ${namedSectionsText}`;
6
7
  }
7
8
  return text;
8
9
  };
9
- const renderNamedSections = namedSections => {
10
+
11
+ const renderNamedSections = (namedSections) => {
10
12
  let text = "";
11
13
  let keys = Object.keys(namedSections);
12
14
  for (const key of keys) {
13
15
  const isLastKey = key === keys[keys.length - 1];
14
16
  const value = namedSections[key];
15
- text += "--- ".concat(key, " ---\n").concat(Array.isArray(value) ? value.join("\n") : value);
17
+ text += `--- ${key} ---
18
+ ${
19
+ Array.isArray(value)
20
+ ? value.join(`
21
+ `)
22
+ : value
23
+ }`;
16
24
  if (!isLastKey) {
17
25
  text += "\n";
18
26
  }
@@ -23,6 +31,7 @@ const renderNamedSections = namedSections => {
23
31
  // https://github.com/Marak/colors.js/blob/master/lib/styles.js
24
32
  // https://stackoverflow.com/a/75985833/2634179
25
33
  const RESET = "\x1b[0m";
34
+
26
35
  const RED = "red";
27
36
  const GREEN = "green";
28
37
  const YELLOW = "yellow";
@@ -32,6 +41,7 @@ const CYAN = "cyan";
32
41
  const GREY = "grey";
33
42
  const WHITE = "white";
34
43
  const BLACK = "black";
44
+
35
45
  const TEXT_COLOR_ANSI_CODES = {
36
46
  [RED]: "\x1b[31m",
37
47
  [GREEN]: "\x1b[32m",
@@ -41,7 +51,7 @@ const TEXT_COLOR_ANSI_CODES = {
41
51
  [CYAN]: "\x1b[36m",
42
52
  [GREY]: "\x1b[90m",
43
53
  [WHITE]: "\x1b[37m",
44
- [BLACK]: "\x1b[30m"
54
+ [BLACK]: "\x1b[30m",
45
55
  };
46
56
  const BACKGROUND_COLOR_ANSI_CODES = {
47
57
  [RED]: "\x1b[41m",
@@ -52,13 +62,13 @@ const BACKGROUND_COLOR_ANSI_CODES = {
52
62
  [CYAN]: "\x1b[46m",
53
63
  [GREY]: "\x1b[100m",
54
64
  [WHITE]: "\x1b[47m",
55
- [BLACK]: "\x1b[40m"
65
+ [BLACK]: "\x1b[40m",
56
66
  };
57
- const createAnsi = ({
58
- supported
59
- }) => {
67
+
68
+ const createAnsi = ({ supported }) => {
60
69
  const ANSI = {
61
70
  supported,
71
+
62
72
  RED,
63
73
  GREEN,
64
74
  YELLOW,
@@ -83,7 +93,7 @@ const createAnsi = ({
83
93
  if (!ansiEscapeCodeForTextColor) {
84
94
  return text;
85
95
  }
86
- return "".concat(ansiEscapeCodeForTextColor).concat(text).concat(RESET);
96
+ return `${ansiEscapeCodeForTextColor}${text}${RESET}`;
87
97
  },
88
98
  backgroundColor: (text, color) => {
89
99
  if (!ANSI.supported) {
@@ -96,12 +106,14 @@ const createAnsi = ({
96
106
  // cannot set background color of blank chars
97
107
  return text;
98
108
  }
99
- const ansiEscapeCodeForBackgroundColor = BACKGROUND_COLOR_ANSI_CODES[color];
109
+ const ansiEscapeCodeForBackgroundColor =
110
+ BACKGROUND_COLOR_ANSI_CODES[color];
100
111
  if (!ansiEscapeCodeForBackgroundColor) {
101
112
  return text;
102
113
  }
103
- return "".concat(ansiEscapeCodeForBackgroundColor).concat(text).concat(RESET);
114
+ return `${ansiEscapeCodeForBackgroundColor}${text}${RESET}`;
104
115
  },
116
+
105
117
  BOLD: "\x1b[1m",
106
118
  UNDERLINE: "\x1b[4m",
107
119
  STRIKE: "\x1b[9m",
@@ -117,47 +129,43 @@ const createAnsi = ({
117
129
  return text;
118
130
  }
119
131
  const ansiEscapeCodeForEffect = effect;
120
- return "".concat(ansiEscapeCodeForEffect).concat(text).concat(RESET);
121
- }
132
+ return `${ansiEscapeCodeForEffect}${text}${RESET}`;
133
+ },
122
134
  };
135
+
123
136
  return ANSI;
124
137
  };
125
138
 
126
- const ANSI = createAnsi({
127
- supported: true
128
- });
139
+ const ANSI = createAnsi({ supported: true });
129
140
 
130
141
  // see also https://github.com/sindresorhus/figures
131
142
 
132
- const createUnicode = ({
133
- supported,
134
- ANSI
135
- }) => {
143
+ const createUnicode = ({ supported, ANSI }) => {
136
144
  const UNICODE = {
137
145
  supported,
138
146
  get COMMAND_RAW() {
139
- return UNICODE.supported ? "\u276F" : ">";
147
+ return UNICODE.supported ? `❯` : `>`;
140
148
  },
141
149
  get OK_RAW() {
142
- return UNICODE.supported ? "\u2714" : "\u221A";
150
+ return UNICODE.supported ? `✔` : `√`;
143
151
  },
144
152
  get FAILURE_RAW() {
145
- return UNICODE.supported ? "\u2716" : "\xD7";
153
+ return UNICODE.supported ? `✖` : `×`;
146
154
  },
147
155
  get DEBUG_RAW() {
148
- return UNICODE.supported ? "\u25C6" : "\u2666";
156
+ return UNICODE.supported ? `◆` : `♦`;
149
157
  },
150
158
  get INFO_RAW() {
151
- return UNICODE.supported ? "\u2139" : "i";
159
+ return UNICODE.supported ? `ℹ` : `i`;
152
160
  },
153
161
  get WARNING_RAW() {
154
- return UNICODE.supported ? "\u26A0" : "\u203C";
162
+ return UNICODE.supported ? `⚠` : `‼`;
155
163
  },
156
164
  get CIRCLE_CROSS_RAW() {
157
- return UNICODE.supported ? "\u24E7" : "(\xD7)";
165
+ return UNICODE.supported ? `ⓧ` : `(×)`;
158
166
  },
159
167
  get CIRCLE_DOTTED_RAW() {
160
- return UNICODE.supported ? "\u25CC" : "*";
168
+ return UNICODE.supported ? `◌` : `*`;
161
169
  },
162
170
  get COMMAND() {
163
171
  return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
@@ -181,26 +189,24 @@ const createUnicode = ({
181
189
  return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
182
190
  },
183
191
  get ELLIPSIS() {
184
- return UNICODE.supported ? "\u2026" : "...";
185
- }
192
+ return UNICODE.supported ? `…` : `...`;
193
+ },
186
194
  };
187
195
  return UNICODE;
188
196
  };
189
197
 
190
198
  const UNICODE = createUnicode({
191
199
  supported: true,
192
- ANSI
200
+ ANSI,
193
201
  });
194
202
 
195
- const inspectBoolean = value => value.toString();
203
+ const inspectBoolean = (value) => value.toString();
196
204
 
197
205
  const inspectNull = () => "null";
198
206
 
199
207
  // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/numeric-separators-style.js
200
208
 
201
- const inspectNumber = (value, {
202
- numericSeparator
203
- }) => {
209
+ const inspectNumber = (value, { numericSeparator }) => {
204
210
  if (isNegativeZero(value)) {
205
211
  return "-0";
206
212
  }
@@ -223,66 +229,65 @@ const inspectNumber = (value, {
223
229
  number,
224
230
  mark = "",
225
231
  sign = "",
226
- power = ""
227
- } = numberString.match(/^(?<number>.*?)(?:(?<mark>e)(?<sign>[+-])?(?<power>\d+))?$/i).groups;
232
+ power = "",
233
+ } = numberString.match(
234
+ /^(?<number>.*?)(?:(?<mark>e)(?<sign>[+-])?(?<power>\d+))?$/i,
235
+ ).groups;
228
236
  const numberWithSeparators = formatNumber(number);
229
237
  const powerWithSeparators = addSeparator(power, {
230
238
  minimumDigits: 5,
231
- groupLength: 3
239
+ groupLength: 3,
232
240
  });
233
- return "".concat(numberWithSeparators).concat(mark).concat(sign).concat(powerWithSeparators);
241
+ return `${numberWithSeparators}${mark}${sign}${powerWithSeparators}`;
234
242
  };
235
243
 
236
244
  // Use this and instead of Object.is(value, -0)
237
245
  // because in some corner cases firefox returns false
238
246
  // for Object.is(-0, -0)
239
- const isNegativeZero = value => {
247
+ const isNegativeZero = (value) => {
240
248
  return value === 0 && 1 / value === -Infinity;
241
249
  };
242
- const formatNumber = numberString => {
250
+
251
+ const formatNumber = (numberString) => {
243
252
  const parts = numberString.split(".");
244
253
  const [integer, fractional] = parts;
254
+
245
255
  if (parts.length === 2) {
246
256
  const integerWithSeparators = addSeparator(integer, {
247
257
  minimumDigits: 5,
248
- groupLength: 3
258
+ groupLength: 3,
249
259
  });
250
- return "".concat(integerWithSeparators, ".").concat(fractional);
260
+ return `${integerWithSeparators}.${fractional}`;
251
261
  }
262
+
252
263
  return addSeparator(integer, {
253
264
  minimumDigits: 5,
254
- groupLength: 3
265
+ groupLength: 3,
255
266
  });
256
267
  };
257
- const addSeparator = (numberString, {
258
- minimumDigits,
259
- groupLength
260
- }) => {
268
+
269
+ const addSeparator = (numberString, { minimumDigits, groupLength }) => {
261
270
  if (numberString[0] === "-") {
262
- return "-".concat(groupDigits(numberString.slice(1), {
271
+ return `-${groupDigits(numberString.slice(1), {
263
272
  minimumDigits,
264
- groupLength
265
- }));
273
+ groupLength,
274
+ })}`;
266
275
  }
267
- return groupDigits(numberString, {
268
- minimumDigits,
269
- groupLength
270
- });
276
+ return groupDigits(numberString, { minimumDigits, groupLength });
271
277
  };
272
- const groupDigits = (digits, {
273
- minimumDigits,
274
- groupLength
275
- }) => {
278
+
279
+ const groupDigits = (digits, { minimumDigits, groupLength }) => {
276
280
  const digitCount = digits.length;
277
281
  if (digitCount < minimumDigits) {
278
282
  return digits;
279
283
  }
280
- let digitsWithSeparator = digits.slice(-3);
281
- let remainingDigits = digits.slice(0, -3);
284
+
285
+ let digitsWithSeparator = digits.slice(-groupLength);
286
+ let remainingDigits = digits.slice(0, -groupLength);
282
287
  while (remainingDigits.length) {
283
- const group = remainingDigits.slice(-3);
284
- remainingDigits = remainingDigits.slice(0, -3);
285
- digitsWithSeparator = "".concat(group, "_").concat(digitsWithSeparator);
288
+ const group = remainingDigits.slice(-groupLength);
289
+ remainingDigits = remainingDigits.slice(0, -groupLength);
290
+ digitsWithSeparator = `${group}_${digitsWithSeparator}`;
286
291
  }
287
292
  return digitsWithSeparator;
288
293
  };
@@ -301,46 +306,50 @@ const groupDigits = (digits, {
301
306
  // return parts.join("_");
302
307
  // };
303
308
 
304
- const DOUBLE_QUOTE = "\"";
305
- const SINGLE_QUOTE = "'";
309
+ const DOUBLE_QUOTE = `"`;
310
+ const SINGLE_QUOTE = `'`;
306
311
  const BACKTICK = "`";
307
- const inspectString = (value, {
308
- quote = "auto",
309
- canUseTemplateString = false,
310
- preserveLineBreaks = false,
311
- quoteDefault = DOUBLE_QUOTE
312
- } = {}) => {
313
- quote = quote === "auto" ? determineQuote(value, {
314
- canUseTemplateString,
315
- quoteDefault
316
- }) : quote;
312
+
313
+ const inspectString = (
314
+ value,
315
+ {
316
+ quote = "auto",
317
+ canUseTemplateString = false,
318
+ preserveLineBreaks = false,
319
+ quoteDefault = DOUBLE_QUOTE,
320
+ } = {},
321
+ ) => {
322
+ quote =
323
+ quote === "auto"
324
+ ? determineQuote(value, { canUseTemplateString, quoteDefault })
325
+ : quote;
317
326
  if (quote === BACKTICK) {
318
- return "`".concat(escapeTemplateStringSpecialCharacters(value), "`");
327
+ return `\`${escapeTemplateStringSpecialCharacters(value)}\``;
319
328
  }
320
- return surroundStringWith(value, {
321
- quote,
322
- preserveLineBreaks
323
- });
329
+ return surroundStringWith(value, { quote, preserveLineBreaks });
324
330
  };
325
331
 
326
332
  // https://github.com/mgenware/string-to-template-literal/blob/main/src/main.ts#L1
327
- const escapeTemplateStringSpecialCharacters = string => {
333
+ const escapeTemplateStringSpecialCharacters = (string) => {
328
334
  string = String(string);
329
335
  let i = 0;
330
336
  let escapedString = "";
331
337
  while (i < string.length) {
332
338
  const char = string[i];
333
339
  i++;
334
- escapedString += isTemplateStringSpecialChar(char) ? "\\".concat(char) : char;
340
+ escapedString += isTemplateStringSpecialChar(char) ? `\\${char}` : char;
335
341
  }
336
342
  return escapedString;
337
343
  };
338
- const isTemplateStringSpecialChar = char => templateStringSpecialChars.indexOf(char) > -1;
344
+
345
+ const isTemplateStringSpecialChar = (char) =>
346
+ templateStringSpecialChars.indexOf(char) > -1;
339
347
  const templateStringSpecialChars = ["\\", "`", "$"];
340
- const determineQuote = (string, {
341
- canUseTemplateString,
342
- quoteDefault = DOUBLE_QUOTE
343
- } = {}) => {
348
+
349
+ const determineQuote = (
350
+ string,
351
+ { canUseTemplateString, quoteDefault = DOUBLE_QUOTE } = {},
352
+ ) => {
344
353
  const containsDoubleQuote = string.includes(DOUBLE_QUOTE);
345
354
  if (!containsDoubleQuote) {
346
355
  return DOUBLE_QUOTE;
@@ -365,18 +374,29 @@ const determineQuote = (string, {
365
374
  }
366
375
  return quoteDefault;
367
376
  };
368
- const inspectChar = (char, {
369
- quote,
370
- preserveLineBreaks
371
- }) => {
377
+
378
+ const inspectChar = (char, { quote, preserveLineBreaks }) => {
372
379
  const point = char.charCodeAt(0);
373
380
  if (preserveLineBreaks && (char === "\n" || char === "\r")) {
374
381
  return char;
375
382
  }
376
- if (char === quote || point === 92 || point < 32 || point > 126 && point < 160 ||
377
- // line separators
378
- point === 8232 || point === 8233) {
379
- const replacement = char === quote ? "\\".concat(quote) : point === 8232 ? "\\u2028" : point === 8233 ? "\\u2029" : meta[point];
383
+ if (
384
+ char === quote ||
385
+ point === 92 ||
386
+ point < 32 ||
387
+ (point > 126 && point < 160) ||
388
+ // line separators
389
+ point === 8232 ||
390
+ point === 8233
391
+ ) {
392
+ const replacement =
393
+ char === quote
394
+ ? `\\${quote}`
395
+ : point === 8232
396
+ ? "\\u2028"
397
+ : point === 8233
398
+ ? "\\u2029"
399
+ : meta[point];
380
400
  return replacement;
381
401
  }
382
402
  return char;
@@ -386,25 +406,19 @@ const inspectChar = (char, {
386
406
  // https://github.com/jsenv/jsenv-inspect/blob/bb11de3adf262b68f71ed82b0a37d4528dd42229/src/internal/string.js#L3
387
407
  // https://github.com/joliss/js-string-escape/blob/master/index.js
388
408
  // http://javascript.crockford.com/remedial.html
389
- const surroundStringWith = (string, {
390
- quote,
391
- preserveLineBreaks
392
- }) => {
409
+ const surroundStringWith = (string, { quote, preserveLineBreaks }) => {
393
410
  let result = "";
394
411
  let last = 0;
395
412
  const lastIndex = string.length;
396
413
  let i = 0;
397
414
  while (i < lastIndex) {
398
415
  const char = string[i];
399
- const replacement = inspectChar(char, {
400
- quote,
401
- preserveLineBreaks
402
- });
416
+ const replacement = inspectChar(char, { quote, preserveLineBreaks });
403
417
  if (char !== replacement) {
404
418
  if (last === i) {
405
419
  result += replacement;
406
420
  } else {
407
- result += "".concat(string.slice(last, i)).concat(replacement);
421
+ result += `${string.slice(last, i)}${replacement}`;
408
422
  }
409
423
  last = i + 1;
410
424
  }
@@ -413,90 +427,105 @@ const surroundStringWith = (string, {
413
427
  if (last !== lastIndex) {
414
428
  result += string.slice(last);
415
429
  }
416
- return "".concat(quote).concat(result).concat(quote);
430
+ return `${quote}${result}${quote}`;
417
431
  };
418
432
 
419
433
  // prettier-ignore
420
- const meta = ['\\x00', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\x07',
421
- // x07
422
- '\\b', '\\t', '\\n', '\\x0B', '\\f', '\\r', '\\x0E', '\\x0F',
423
- // x0F
424
- '\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17',
425
- // x17
426
- '\\x18', '\\x19', '\\x1A', '\\x1B', '\\x1C', '\\x1D', '\\x1E', '\\x1F',
427
- // x1F
428
- '', '', '', '', '', '', '', "\\'", '', '', '', '', '', '', '', '',
429
- // x2F
430
- '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
431
- // x3F
432
- '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
433
- // x4F
434
- '', '', '', '', '', '', '', '', '', '', '', '', '\\\\', '', '', '',
435
- // x5F
436
- '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
437
- // x6F
438
- '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\\x7F',
439
- // x7F
440
- '\\x80', '\\x81', '\\x82', '\\x83', '\\x84', '\\x85', '\\x86', '\\x87',
441
- // x87
442
- '\\x88', '\\x89', '\\x8A', '\\x8B', '\\x8C', '\\x8D', '\\x8E', '\\x8F',
443
- // x8F
444
- '\\x90', '\\x91', '\\x92', '\\x93', '\\x94', '\\x95', '\\x96', '\\x97',
445
- // x97
446
- '\\x98', '\\x99', '\\x9A', '\\x9B', '\\x9C', '\\x9D', '\\x9E', '\\x9F' // x9F
434
+ const meta = [
435
+ '\\x00', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\x07', // x07
436
+ '\\b', '\\t', '\\n', '\\x0B', '\\f', '\\r', '\\x0E', '\\x0F', // x0F
437
+ '\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17', // x17
438
+ '\\x18', '\\x19', '\\x1A', '\\x1B', '\\x1C', '\\x1D', '\\x1E', '\\x1F', // x1F
439
+ '', '', '', '', '', '', '', "\\'", '', '', '', '', '', '', '', '', // x2F
440
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x3F
441
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x4F
442
+ '', '', '', '', '', '', '', '', '', '', '', '', '\\\\', '', '', '', // x5F
443
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x6F
444
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\\x7F', // x7F
445
+ '\\x80', '\\x81', '\\x82', '\\x83', '\\x84', '\\x85', '\\x86', '\\x87', // x87
446
+ '\\x88', '\\x89', '\\x8A', '\\x8B', '\\x8C', '\\x8D', '\\x8E', '\\x8F', // x8F
447
+ '\\x90', '\\x91', '\\x92', '\\x93', '\\x94', '\\x95', '\\x96', '\\x97', // x97
448
+ '\\x98', '\\x99', '\\x9A', '\\x9B', '\\x9C', '\\x9D', '\\x9E', '\\x9F', // x9F
447
449
  ];
448
450
 
449
- const inspectSymbol = (value, {
450
- nestedHumanize,
451
- parenthesis
452
- }) => {
451
+ const inspectSymbol = (value, { nestedHumanize, parenthesis }) => {
453
452
  const symbolDescription = symbolToDescription(value);
454
- const symbolDescriptionSource = symbolDescription ? nestedHumanize(symbolDescription) : "";
455
- const symbolSource = "Symbol(".concat(symbolDescriptionSource, ")");
456
- if (parenthesis) return "".concat(symbolSource);
453
+ const symbolDescriptionSource = symbolDescription
454
+ ? nestedHumanize(symbolDescription)
455
+ : "";
456
+ const symbolSource = `Symbol(${symbolDescriptionSource})`;
457
+
458
+ if (parenthesis) return `${symbolSource}`;
457
459
  return symbolSource;
458
460
  };
459
- const symbolToDescription = "description" in Symbol.prototype ? symbol => symbol.description : symbol => {
460
- const toStringResult = symbol.toString();
461
- const openingParenthesisIndex = toStringResult.indexOf("(");
462
- const closingParenthesisIndex = toStringResult.indexOf(")");
463
- const symbolDescription = toStringResult.slice(openingParenthesisIndex + 1, closingParenthesisIndex);
464
- return symbolDescription;
465
- };
461
+
462
+ const symbolToDescription =
463
+ "description" in Symbol.prototype
464
+ ? (symbol) => symbol.description
465
+ : (symbol) => {
466
+ const toStringResult = symbol.toString();
467
+ const openingParenthesisIndex = toStringResult.indexOf("(");
468
+ const closingParenthesisIndex = toStringResult.indexOf(")");
469
+ const symbolDescription = toStringResult.slice(
470
+ openingParenthesisIndex + 1,
471
+ closingParenthesisIndex,
472
+ );
473
+ return symbolDescription;
474
+ };
466
475
 
467
476
  const inspectUndefined = () => "undefined";
468
477
 
469
- const inspectBigInt = value => {
470
- return "".concat(value, "n");
478
+ const inspectBigInt = (value) => {
479
+ return `${value}n`;
480
+ };
481
+
482
+ const prefixFirstAndIndentRemainingLines = (
483
+ text,
484
+ { prefix, indentation, trimLines, trimLastLine },
485
+ ) => {
486
+ const lines = text.split(/\r?\n/);
487
+ const firstLine = lines.shift();
488
+ if (indentation === undefined) {
489
+ if (prefix) {
490
+ indentation = " "; // prefix + space
491
+ } else {
492
+ indentation = "";
493
+ }
494
+ }
495
+ let result = prefix ? `${prefix} ${firstLine}` : firstLine;
496
+ let i = 0;
497
+ while (i < lines.length) {
498
+ const line = trimLines ? lines[i].trim() : lines[i];
499
+ i++;
500
+ result += line.length
501
+ ? `\n${indentation}${line}`
502
+ : trimLastLine && i === lines.length
503
+ ? ""
504
+ : `\n`;
505
+ }
506
+ return result;
471
507
  };
472
508
 
473
- const preNewLineAndIndentation = (value, {
474
- depth,
475
- indentUsingTab,
476
- indentSize
477
- }) => {
478
- return "".concat(newLineAndIndent({
509
+ const preNewLineAndIndentation = (
510
+ value,
511
+ { depth = 0, indentUsingTab, indentSize },
512
+ ) => {
513
+ return `${newLineAndIndent({
479
514
  count: depth + 1,
480
515
  useTabs: indentUsingTab,
481
- size: indentSize
482
- })).concat(value);
516
+ size: indentSize,
517
+ })}${value}`;
483
518
  };
484
- const postNewLineAndIndentation = ({
485
- depth,
486
- indentUsingTab,
487
- indentSize
488
- }) => {
519
+
520
+ const postNewLineAndIndentation = ({ depth, indentUsingTab, indentSize }) => {
489
521
  return newLineAndIndent({
490
522
  count: depth,
491
523
  useTabs: indentUsingTab,
492
- size: indentSize
524
+ size: indentSize,
493
525
  });
494
526
  };
495
- const newLineAndIndent = ({
496
- count,
497
- useTabs,
498
- size
499
- }) => {
527
+
528
+ const newLineAndIndent = ({ count, useTabs, size }) => {
500
529
  if (useTabs) {
501
530
  // eslint-disable-next-line prefer-template
502
531
  return "\n" + "\t".repeat(count);
@@ -504,118 +533,116 @@ const newLineAndIndent = ({
504
533
  // eslint-disable-next-line prefer-template
505
534
  return "\n" + " ".repeat(count * size);
506
535
  };
507
- const wrapNewLineAndIndentation = (value, {
508
- depth,
509
- indentUsingTab,
510
- indentSize
511
- }) => {
512
- return "".concat(preNewLineAndIndentation(value, {
513
- depth,
514
- indentUsingTab,
515
- indentSize
516
- })).concat(postNewLineAndIndentation({
536
+
537
+ const wrapNewLineAndIndentation = (
538
+ value,
539
+ { depth = 0, indentUsingTab, indentSize },
540
+ ) => {
541
+ return `${preNewLineAndIndentation(value, {
517
542
  depth,
518
543
  indentUsingTab,
519
- indentSize
520
- }));
544
+ indentSize,
545
+ })}${postNewLineAndIndentation({ depth, indentUsingTab, indentSize })}`;
521
546
  };
522
547
 
523
- const inspectConstructor = (value, {
524
- parenthesis,
525
- useNew
526
- }) => {
548
+ const inspectConstructor = (value, { parenthesis, useNew }) => {
527
549
  let formattedString = value;
528
550
  if (parenthesis) {
529
- formattedString = "(".concat(value, ")");
551
+ formattedString = `(${value})`;
530
552
  }
531
553
  if (useNew) {
532
- formattedString = "new ".concat(formattedString);
554
+ formattedString = `new ${formattedString}`;
533
555
  }
534
556
  return formattedString;
535
557
  };
536
558
 
537
- const inspectArray = (value, {
538
- seen = [],
539
- nestedHumanize,
540
- depth,
541
- indentUsingTab,
542
- indentSize,
543
- parenthesis,
544
- useNew
545
- }) => {
559
+ const inspectArray = (
560
+ value,
561
+ {
562
+ seen = [],
563
+ nestedHumanize,
564
+ depth,
565
+ indentUsingTab,
566
+ indentSize,
567
+ parenthesis,
568
+ useNew,
569
+ },
570
+ ) => {
546
571
  if (seen.indexOf(value) > -1) {
547
572
  return "Symbol.for('circular')";
548
573
  }
549
574
  seen.push(value);
575
+
550
576
  let valuesSource = "";
551
577
  let i = 0;
552
578
  const j = value.length;
579
+
553
580
  while (i < j) {
554
- const valueSource = value.hasOwnProperty(i) ? nestedHumanize(value[i], {
555
- seen
556
- }) : "";
581
+ const valueSource = value.hasOwnProperty(i)
582
+ ? nestedHumanize(value[i], { seen })
583
+ : "";
557
584
  if (i === 0) {
558
585
  valuesSource += valueSource;
559
586
  } else {
560
- valuesSource += ",".concat(preNewLineAndIndentation(valueSource, {
587
+ valuesSource += `,${preNewLineAndIndentation(valueSource, {
561
588
  depth,
562
589
  indentUsingTab,
563
- indentSize
564
- }));
590
+ indentSize,
591
+ })}`;
565
592
  }
566
593
  i++;
567
594
  }
595
+
568
596
  let arraySource;
569
597
  if (valuesSource.length) {
570
598
  arraySource = wrapNewLineAndIndentation(valuesSource, {
571
599
  depth,
572
600
  indentUsingTab,
573
- indentSize
601
+ indentSize,
574
602
  });
575
603
  } else {
576
604
  arraySource = "";
577
605
  }
578
- arraySource = "[".concat(arraySource, "]");
579
- return inspectConstructor(arraySource, {
580
- parenthesis,
581
- useNew
582
- });
606
+
607
+ arraySource = `[${arraySource}]`;
608
+
609
+ return inspectConstructor(arraySource, { parenthesis, useNew });
583
610
  };
584
611
 
585
- const inspectBigIntObject = (value, {
586
- nestedHumanize
587
- }) => {
612
+ const inspectBigIntObject = (value, { nestedHumanize }) => {
588
613
  const bigIntSource = nestedHumanize(value.valueOf());
589
- return "BigInt(".concat(bigIntSource, ")");
614
+
615
+ return `BigInt(${bigIntSource})`;
590
616
  };
591
617
 
592
- const inspectBooleanObject = (value, {
593
- nestedHumanize,
594
- useNew,
595
- parenthesis
596
- }) => {
618
+ const inspectBooleanObject = (
619
+ value,
620
+ { nestedHumanize, useNew, parenthesis },
621
+ ) => {
597
622
  const booleanSource = nestedHumanize(value.valueOf());
598
- return inspectConstructor("Boolean(".concat(booleanSource, ")"), {
623
+ return inspectConstructor(`Boolean(${booleanSource})`, {
599
624
  useNew,
600
- parenthesis
625
+ parenthesis,
601
626
  });
602
627
  };
603
628
 
604
- const inspectError = (error, {
605
- nestedHumanize,
606
- useNew,
607
- parenthesis
608
- }) => {
629
+ const inspectError = (
630
+ error,
631
+ { nestedHumanize, useNew, parenthesis },
632
+ ) => {
609
633
  const messageSource = nestedHumanize(error.message);
610
- const errorSource = inspectConstructor("".concat(errorToConstructorName(error), "(").concat(messageSource, ")"), {
611
- useNew,
612
- parenthesis
613
- });
634
+
635
+ const errorSource = inspectConstructor(
636
+ `${errorToConstructorName(error)}(${messageSource})`,
637
+ {
638
+ useNew,
639
+ parenthesis,
640
+ },
641
+ );
614
642
  return errorSource;
615
643
  };
616
- const errorToConstructorName = ({
617
- name
618
- }) => {
644
+
645
+ const errorToConstructorName = ({ name }) => {
619
646
  if (derivedErrorNameArray.includes(name)) {
620
647
  return name;
621
648
  }
@@ -623,148 +650,153 @@ const errorToConstructorName = ({
623
650
  };
624
651
 
625
652
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types
626
- const derivedErrorNameArray = ["EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError"];
653
+ const derivedErrorNameArray = [
654
+ "EvalError",
655
+ "RangeError",
656
+ "ReferenceError",
657
+ "SyntaxError",
658
+ "TypeError",
659
+ "URIError",
660
+ ];
627
661
 
628
- const inspectDate = (value, {
629
- nestedHumanize,
630
- useNew,
631
- parenthesis
632
- }) => {
662
+ const inspectDate = (value, { nestedHumanize, useNew, parenthesis }) => {
633
663
  const dateSource = nestedHumanize(value.valueOf(), {
634
- numericSeparator: false
635
- });
636
- return inspectConstructor("Date(".concat(dateSource, ")"), {
637
- useNew,
638
- parenthesis
664
+ numericSeparator: false,
639
665
  });
666
+ return inspectConstructor(`Date(${dateSource})`, { useNew, parenthesis });
640
667
  };
641
668
 
642
- const inspectFunction = (value, {
643
- showFunctionBody,
644
- parenthesis,
645
- depth
646
- }) => {
669
+ const inspectFunction = (
670
+ value,
671
+ { showFunctionBody, parenthesis, depth },
672
+ ) => {
647
673
  let functionSource;
648
674
  if (showFunctionBody) {
649
675
  functionSource = value.toString();
650
676
  } else {
651
677
  const isArrowFunction = value.prototype === undefined;
652
- const head = isArrowFunction ? "() =>" : "function ".concat(depth === 0 ? value.name : "", "()");
653
- functionSource = "".concat(head, " {/* hidden */}");
678
+ const head = isArrowFunction
679
+ ? "() =>"
680
+ : `function ${depth === 0 ? value.name : ""}()`;
681
+ functionSource = `${head} {/* hidden */}`;
654
682
  }
683
+
655
684
  if (parenthesis) {
656
- return "(".concat(functionSource, ")");
685
+ return `(${functionSource})`;
657
686
  }
658
687
  return functionSource;
659
688
  };
660
689
 
661
- const inspectNumberObject = (value, {
662
- nestedHumanize,
663
- useNew,
664
- parenthesis
665
- }) => {
690
+ const inspectNumberObject = (
691
+ value,
692
+ { nestedHumanize, useNew, parenthesis },
693
+ ) => {
666
694
  const numberSource = nestedHumanize(value.valueOf());
667
- return inspectConstructor("Number(".concat(numberSource, ")"), {
668
- useNew,
669
- parenthesis
670
- });
695
+ return inspectConstructor(`Number(${numberSource})`, { useNew, parenthesis });
671
696
  };
672
697
 
673
- const inspectObject = (value, {
674
- nestedHumanize,
675
- seen = [],
676
- depth,
677
- indentUsingTab,
678
- indentSize,
679
- objectConstructor,
680
- parenthesis,
681
- useNew
682
- }) => {
698
+ const inspectObject = (
699
+ value,
700
+ {
701
+ nestedHumanize,
702
+ seen = [],
703
+ depth,
704
+ indentUsingTab,
705
+ indentSize,
706
+ objectConstructor,
707
+ parenthesis,
708
+ useNew,
709
+ },
710
+ ) => {
683
711
  if (seen.indexOf(value) > -1) return "Symbol.for('circular')";
712
+
684
713
  seen.push(value);
714
+
685
715
  const propertySourceArray = [];
686
- Object.getOwnPropertyNames(value).forEach(propertyName => {
716
+ Object.getOwnPropertyNames(value).forEach((propertyName) => {
687
717
  const propertyNameAsNumber = parseInt(propertyName, 10);
688
- const propertyNameSource = nestedHumanize(Number.isInteger(propertyNameAsNumber) ? propertyNameAsNumber : propertyName);
718
+ const propertyNameSource = nestedHumanize(
719
+ Number.isInteger(propertyNameAsNumber)
720
+ ? propertyNameAsNumber
721
+ : propertyName,
722
+ );
689
723
  propertySourceArray.push({
690
724
  nameOrSymbolSource: propertyNameSource,
691
- valueSource: nestedHumanize(value[propertyName], {
692
- seen
693
- })
725
+ valueSource: nestedHumanize(value[propertyName], { seen }),
694
726
  });
695
727
  });
696
- Object.getOwnPropertySymbols(value).forEach(symbol => {
728
+ Object.getOwnPropertySymbols(value).forEach((symbol) => {
697
729
  propertySourceArray.push({
698
- nameOrSymbolSource: "[".concat(nestedHumanize(symbol), "]"),
699
- valueSource: nestedHumanize(value[symbol], {
700
- seen
701
- })
730
+ nameOrSymbolSource: `[${nestedHumanize(symbol)}]`,
731
+ valueSource: nestedHumanize(value[symbol], { seen }),
702
732
  });
703
733
  });
734
+
704
735
  let propertiesSource = "";
705
- propertySourceArray.forEach(({
706
- nameOrSymbolSource,
707
- valueSource
708
- }, index) => {
736
+ propertySourceArray.forEach(({ nameOrSymbolSource, valueSource }, index) => {
709
737
  if (index === 0) {
710
- propertiesSource += "".concat(nameOrSymbolSource, ": ").concat(valueSource);
738
+ propertiesSource += `${nameOrSymbolSource}: ${valueSource}`;
711
739
  } else {
712
- propertiesSource += ",".concat(preNewLineAndIndentation("".concat(nameOrSymbolSource, ": ").concat(valueSource), {
713
- depth,
714
- indentUsingTab,
715
- indentSize
716
- }));
740
+ propertiesSource += `,${preNewLineAndIndentation(
741
+ `${nameOrSymbolSource}: ${valueSource}`,
742
+ {
743
+ depth,
744
+ indentUsingTab,
745
+ indentSize,
746
+ },
747
+ )}`;
717
748
  }
718
749
  });
750
+
719
751
  let objectSource;
720
752
  if (propertiesSource.length) {
721
- objectSource = "".concat(wrapNewLineAndIndentation(propertiesSource, {
753
+ objectSource = `${wrapNewLineAndIndentation(propertiesSource, {
722
754
  depth,
723
755
  indentUsingTab,
724
- indentSize
725
- }));
756
+ indentSize,
757
+ })}`;
726
758
  } else {
727
759
  objectSource = "";
728
760
  }
761
+
729
762
  if (objectConstructor) {
730
- objectSource = "Object({".concat(objectSource, "})");
763
+ objectSource = `Object({${objectSource}})`;
731
764
  } else {
732
- objectSource = "{".concat(objectSource, "}");
765
+ objectSource = `{${objectSource}}`;
733
766
  }
734
- return inspectConstructor(objectSource, {
735
- parenthesis,
736
- useNew
737
- });
767
+
768
+ return inspectConstructor(objectSource, { parenthesis, useNew });
738
769
  };
739
770
 
740
- const inspectRegExp = value => value.toString();
771
+ const inspectRegExp = (value) => value.toString();
741
772
 
742
- const inspectStringObject = (value, {
743
- nestedHumanize,
744
- useNew,
745
- parenthesis
746
- }) => {
773
+ const inspectStringObject = (
774
+ value,
775
+ { nestedHumanize, useNew, parenthesis },
776
+ ) => {
747
777
  const stringSource = nestedHumanize(value.valueOf());
748
- return inspectConstructor("String(".concat(stringSource, ")"), {
749
- useNew,
750
- parenthesis
751
- });
778
+
779
+ return inspectConstructor(`String(${stringSource})`, { useNew, parenthesis });
752
780
  };
753
781
 
754
782
  // tslint:disable:ordered-imports
755
783
 
756
- const humanize = (value, {
757
- parenthesis = false,
758
- quote = "auto",
759
- canUseTemplateString = true,
760
- useNew = false,
761
- objectConstructor = false,
762
- showFunctionBody = false,
763
- indentUsingTab = false,
764
- indentSize = 2,
765
- numericSeparator = true,
766
- preserveLineBreaks = false
767
- } = {}) => {
784
+
785
+ const humanize = (
786
+ value,
787
+ {
788
+ parenthesis = false,
789
+ quote = "auto",
790
+ canUseTemplateString = true,
791
+ useNew = false,
792
+ objectConstructor = false,
793
+ showFunctionBody = false,
794
+ indentUsingTab = false,
795
+ indentSize = 2,
796
+ numericSeparator = true,
797
+ preserveLineBreaks = false,
798
+ } = {},
799
+ ) => {
768
800
  const scopedHumanize = (scopedValue, scopedOptions) => {
769
801
  const options = {
770
802
  ...scopedOptions,
@@ -772,12 +804,13 @@ const humanize = (value, {
772
804
  return scopedHumanize(nestedValue, {
773
805
  ...scopedOptions,
774
806
  depth: scopedOptions.depth + 1,
775
- ...nestedOptions
807
+ ...nestedOptions,
776
808
  });
777
- }
809
+ },
778
810
  };
779
811
  return humanizeValue(scopedValue, options);
780
812
  };
813
+
781
814
  return scopedHumanize(value, {
782
815
  parenthesis,
783
816
  quote,
@@ -789,10 +822,12 @@ const humanize = (value, {
789
822
  indentSize,
790
823
  numericSeparator,
791
824
  preserveLineBreaks,
792
- depth: 0
825
+ depth: 0,
793
826
  });
794
827
  };
828
+
795
829
  const humanizeMethodSymbol = Symbol.for("inspect");
830
+
796
831
  const humanizeValue = (value, options) => {
797
832
  const customHumanize = value && value[humanizeMethodSymbol];
798
833
  if (customHumanize) {
@@ -808,12 +843,16 @@ const humanizeValue = (value, options) => {
808
843
  if (compositeStringifier) {
809
844
  return compositeStringifier(value, options);
810
845
  }
811
- return inspectConstructor("".concat(compositeType, "(").concat(inspectObject(value, options), ")"), {
812
- ...options,
813
- parenthesis: false
814
- });
846
+ return inspectConstructor(
847
+ `${compositeType}(${inspectObject(value, options)})`,
848
+ {
849
+ ...options,
850
+ parenthesis: false,
851
+ },
852
+ );
815
853
  };
816
- const primitiveTypeFromValue = value => {
854
+
855
+ const primitiveTypeFromValue = (value) => {
817
856
  if (value === null) {
818
857
  return "null";
819
858
  }
@@ -830,9 +869,9 @@ const primitiveStringifiers = {
830
869
  string: inspectString,
831
870
  symbol: inspectSymbol,
832
871
  undefined: inspectUndefined,
833
- bigint: inspectBigInt
872
+ bigint: inspectBigInt,
834
873
  };
835
- const compositeTypeFromObject = object => {
874
+ const compositeTypeFromObject = (object) => {
836
875
  if (typeof object === "object" && Object.getPrototypeOf(object) === null) {
837
876
  return "Object";
838
877
  }
@@ -848,9 +887,8 @@ const compositeTypeFromObject = object => {
848
887
  }
849
888
  return tagName;
850
889
  };
851
- const {
852
- toString
853
- } = Object.prototype;
890
+ const { toString } = Object.prototype;
891
+
854
892
  const compositeStringifiers = {
855
893
  Array: inspectArray,
856
894
  BigInt: inspectBigIntObject,
@@ -861,40 +899,45 @@ const compositeStringifiers = {
861
899
  Number: inspectNumberObject,
862
900
  Object: inspectObject,
863
901
  RegExp: inspectRegExp,
864
- String: inspectStringObject
902
+ String: inspectStringObject,
865
903
  };
866
904
 
867
- const getPrecision = number => {
905
+ const getPrecision = (number) => {
868
906
  if (Math.floor(number) === number) return 0;
869
907
  const [, decimals] = number.toString().split(".");
870
908
  return decimals.length || 0;
871
909
  };
872
- const setRoundedPrecision = (number, {
873
- decimals = 1,
874
- decimalsWhenSmall = decimals
875
- } = {}) => {
910
+
911
+ const setRoundedPrecision = (
912
+ number,
913
+ { decimals = 1, decimalsWhenSmall = decimals } = {},
914
+ ) => {
876
915
  return setDecimalsPrecision(number, {
877
916
  decimals,
878
917
  decimalsWhenSmall,
879
- transform: Math.round
918
+ transform: Math.round,
880
919
  });
881
920
  };
882
- const setPrecision = (number, {
883
- decimals = 1,
884
- decimalsWhenSmall = decimals
885
- } = {}) => {
921
+
922
+ const setPrecision = (
923
+ number,
924
+ { decimals = 1, decimalsWhenSmall = decimals } = {},
925
+ ) => {
886
926
  return setDecimalsPrecision(number, {
887
927
  decimals,
888
928
  decimalsWhenSmall,
889
- transform: parseInt
929
+ transform: parseInt,
890
930
  });
891
931
  };
892
- const setDecimalsPrecision = (number, {
893
- transform,
894
- decimals,
895
- // max decimals for number in [-Infinity, -1[]1, Infinity]
896
- decimalsWhenSmall // max decimals for number in [-1,1]
897
- } = {}) => {
932
+
933
+ const setDecimalsPrecision = (
934
+ number,
935
+ {
936
+ transform,
937
+ decimals, // max decimals for number in [-Infinity, -1[]1, Infinity]
938
+ decimalsWhenSmall, // max decimals for number in [-1,1]
939
+ } = {},
940
+ ) => {
898
941
  if (number === 0) {
899
942
  return 0;
900
943
  }
@@ -933,35 +976,34 @@ const setDecimalsPrecision = (number, {
933
976
  // return numberTruncated
934
977
  // }
935
978
 
936
- const humanizeEllapsedTime = (ms, {
937
- short
938
- } = {}) => {
979
+ const humanizeEllapsedTime = (ms, { short } = {}) => {
939
980
  if (ms < 1000) {
940
981
  return short ? "0s" : "0 second";
941
982
  }
942
- const {
943
- primary,
944
- remaining
945
- } = parseMs(ms);
983
+ const { primary, remaining } = parseMs(ms);
946
984
  if (!remaining) {
947
985
  return inspectEllapsedUnit(primary, short);
948
986
  }
949
- return "".concat(inspectEllapsedUnit(primary, short), " and ").concat(inspectEllapsedUnit(remaining, short));
987
+ return `${inspectEllapsedUnit(primary, short)} and ${inspectEllapsedUnit(
988
+ remaining,
989
+ short,
990
+ )}`;
950
991
  };
951
992
  const inspectEllapsedUnit = (unit, short) => {
952
- const count = unit.name === "second" ? Math.floor(unit.count) : Math.round(unit.count);
993
+ const count =
994
+ unit.name === "second" ? Math.floor(unit.count) : Math.round(unit.count);
953
995
  let name = unit.name;
954
996
  if (short) {
955
997
  name = unitShort[name];
956
998
  if (count <= 1) {
957
- return "".concat(count).concat(name);
999
+ return `${count}${name}`;
958
1000
  }
959
- return "".concat(count).concat(name, "s");
1001
+ return `${count}${name}s`;
960
1002
  }
961
1003
  if (count <= 1) {
962
- return "".concat(count, " ").concat(name);
1004
+ return `${count} ${name}`;
963
1005
  }
964
- return "".concat(count, " ").concat(name, "s");
1006
+ return `${count} ${name}s`;
965
1007
  };
966
1008
  const unitShort = {
967
1009
  year: "y",
@@ -970,13 +1012,13 @@ const unitShort = {
970
1012
  day: "d",
971
1013
  hour: "h",
972
1014
  minute: "m",
973
- second: "s"
1015
+ second: "s",
974
1016
  };
975
- const humanizeDuration = (ms, {
976
- short,
977
- rounded = true,
978
- decimals
979
- } = {}) => {
1017
+
1018
+ const humanizeDuration = (
1019
+ ms,
1020
+ { short, rounded = true, decimals } = {},
1021
+ ) => {
980
1022
  // ignore ms below meaningfulMs so that:
981
1023
  // humanizeDuration(0.5) -> "0 second"
982
1024
  // humanizeDuration(1.1) -> "0.001 second" (and not "0.0011 second")
@@ -987,62 +1029,55 @@ const humanizeDuration = (ms, {
987
1029
  if (ms < 1) {
988
1030
  return short ? "0s" : "0 second";
989
1031
  }
990
- const {
991
- primary,
992
- remaining
993
- } = parseMs(ms);
1032
+ const { primary, remaining } = parseMs(ms);
994
1033
  if (!remaining) {
995
1034
  return humanizeDurationUnit(primary, {
996
- decimals: decimals === undefined ? primary.name === "second" ? 1 : 0 : decimals,
1035
+ decimals:
1036
+ decimals === undefined ? (primary.name === "second" ? 1 : 0) : decimals,
997
1037
  short,
998
- rounded
1038
+ rounded,
999
1039
  });
1000
1040
  }
1001
- return "".concat(humanizeDurationUnit(primary, {
1041
+ return `${humanizeDurationUnit(primary, {
1002
1042
  decimals: decimals === undefined ? 0 : decimals,
1003
1043
  short,
1004
- rounded
1005
- }), " and ").concat(humanizeDurationUnit(remaining, {
1044
+ rounded,
1045
+ })} and ${humanizeDurationUnit(remaining, {
1006
1046
  decimals: decimals === undefined ? 0 : decimals,
1007
1047
  short,
1008
- rounded
1009
- }));
1048
+ rounded,
1049
+ })}`;
1010
1050
  };
1011
- const humanizeDurationUnit = (unit, {
1012
- decimals,
1013
- short,
1014
- rounded
1015
- }) => {
1016
- const count = rounded ? setRoundedPrecision(unit.count, {
1017
- decimals
1018
- }) : setPrecision(unit.count, {
1019
- decimals
1020
- });
1051
+ const humanizeDurationUnit = (unit, { decimals, short, rounded }) => {
1052
+ const count = rounded
1053
+ ? setRoundedPrecision(unit.count, { decimals })
1054
+ : setPrecision(unit.count, { decimals });
1021
1055
  let name = unit.name;
1022
1056
  if (short) {
1023
1057
  name = unitShort[name];
1024
- return "".concat(count).concat(name);
1058
+ return `${count}${name}`;
1025
1059
  }
1026
1060
  if (count <= 1) {
1027
- return "".concat(count, " ").concat(name);
1061
+ return `${count} ${name}`;
1028
1062
  }
1029
- return "".concat(count, " ").concat(name, "s");
1063
+ return `${count} ${name}s`;
1030
1064
  };
1031
1065
  const MS_PER_UNITS = {
1032
- year: 31557600000,
1033
- month: 2629000000,
1034
- week: 604800000,
1035
- day: 86400000,
1036
- hour: 3600000,
1037
- minute: 60000,
1038
- second: 1000
1066
+ year: 31_557_600_000,
1067
+ month: 2_629_000_000,
1068
+ week: 604_800_000,
1069
+ day: 86_400_000,
1070
+ hour: 3_600_000,
1071
+ minute: 60_000,
1072
+ second: 1000,
1039
1073
  };
1040
- const parseMs = ms => {
1074
+
1075
+ const parseMs = (ms) => {
1041
1076
  const unitNames = Object.keys(MS_PER_UNITS);
1042
1077
  const smallestUnitName = unitNames[unitNames.length - 1];
1043
1078
  let firstUnitName = smallestUnitName;
1044
1079
  let firstUnitCount = ms / MS_PER_UNITS[smallestUnitName];
1045
- const firstUnitIndex = unitNames.findIndex(unitName => {
1080
+ const firstUnitIndex = unitNames.findIndex((unitName) => {
1046
1081
  if (unitName === smallestUnitName) {
1047
1082
  return false;
1048
1083
  }
@@ -1059,8 +1094,8 @@ const parseMs = ms => {
1059
1094
  return {
1060
1095
  primary: {
1061
1096
  name: firstUnitName,
1062
- count: firstUnitCount
1063
- }
1097
+ count: firstUnitCount,
1098
+ },
1064
1099
  };
1065
1100
  }
1066
1101
  const remainingMs = ms - firstUnitCount * MS_PER_UNITS[firstUnitName];
@@ -1074,51 +1109,42 @@ const parseMs = ms => {
1074
1109
  return {
1075
1110
  primary: {
1076
1111
  name: firstUnitName,
1077
- count: firstUnitCount
1078
- }
1112
+ count: firstUnitCount,
1113
+ },
1079
1114
  };
1080
1115
  }
1081
1116
  // - 1 year and 1 month is great
1082
1117
  return {
1083
1118
  primary: {
1084
1119
  name: firstUnitName,
1085
- count: firstUnitCount
1120
+ count: firstUnitCount,
1086
1121
  },
1087
1122
  remaining: {
1088
1123
  name: remainingUnitName,
1089
- count: remainingUnitCount
1090
- }
1124
+ count: remainingUnitCount,
1125
+ },
1091
1126
  };
1092
1127
  };
1093
1128
 
1094
- const humanizeFileSize = (numberOfBytes, {
1095
- decimals,
1096
- short
1097
- } = {}) => {
1098
- return inspectBytes(numberOfBytes, {
1099
- decimals,
1100
- short
1101
- });
1129
+ const humanizeFileSize = (numberOfBytes, { decimals, short } = {}) => {
1130
+ return inspectBytes(numberOfBytes, { decimals, short });
1102
1131
  };
1103
- const humanizeMemory = (metricValue, {
1104
- decimals,
1105
- short
1106
- } = {}) => {
1107
- return inspectBytes(metricValue, {
1108
- decimals,
1109
- fixedDecimals: true,
1110
- short
1111
- });
1132
+
1133
+ const humanizeMemory = (metricValue, { decimals, short } = {}) => {
1134
+ return inspectBytes(metricValue, { decimals, fixedDecimals: true, short });
1112
1135
  };
1113
- const inspectBytes = (number, {
1114
- fixedDecimals = false,
1115
- decimals,
1116
- short
1117
- } = {}) => {
1136
+
1137
+ const inspectBytes = (
1138
+ number,
1139
+ { fixedDecimals = false, decimals, short } = {},
1140
+ ) => {
1118
1141
  if (number === 0) {
1119
- return "0 B";
1142
+ return `0 B`;
1120
1143
  }
1121
- const exponent = Math.min(Math.floor(Math.log10(number) / 3), BYTE_UNITS.length - 1);
1144
+ const exponent = Math.min(
1145
+ Math.floor(Math.log10(number) / 3),
1146
+ BYTE_UNITS.length - 1,
1147
+ );
1122
1148
  const unitNumber = number / Math.pow(1000, exponent);
1123
1149
  const unitName = BYTE_UNITS[exponent];
1124
1150
  if (decimals === undefined) {
@@ -1130,41 +1156,43 @@ const inspectBytes = (number, {
1130
1156
  }
1131
1157
  const unitNumberRounded = setRoundedPrecision(unitNumber, {
1132
1158
  decimals,
1133
- decimalsWhenSmall: 1
1159
+ decimalsWhenSmall: 1,
1134
1160
  });
1135
- const value = fixedDecimals ? unitNumberRounded.toFixed(decimals) : unitNumberRounded;
1161
+ const value = fixedDecimals
1162
+ ? unitNumberRounded.toFixed(decimals)
1163
+ : unitNumberRounded;
1136
1164
  if (short) {
1137
- return "".concat(value).concat(unitName);
1165
+ return `${value}${unitName}`;
1138
1166
  }
1139
- return "".concat(value, " ").concat(unitName);
1167
+ return `${value} ${unitName}`;
1140
1168
  };
1169
+
1141
1170
  const BYTE_UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
1142
1171
 
1143
- const distributePercentages = (namedNumbers, {
1144
- maxPrecisionHint = 2
1145
- } = {}) => {
1172
+ const distributePercentages = (
1173
+ namedNumbers,
1174
+ { maxPrecisionHint = 2 } = {},
1175
+ ) => {
1146
1176
  const numberNames = Object.keys(namedNumbers);
1147
1177
  if (numberNames.length === 0) {
1148
1178
  return {};
1149
1179
  }
1150
1180
  if (numberNames.length === 1) {
1151
1181
  const firstNumberName = numberNames[0];
1152
- return {
1153
- [firstNumberName]: "100 %"
1154
- };
1182
+ return { [firstNumberName]: "100 %" };
1155
1183
  }
1156
- const numbers = numberNames.map(name => namedNumbers[name]);
1184
+ const numbers = numberNames.map((name) => namedNumbers[name]);
1157
1185
  const total = numbers.reduce((sum, value) => sum + value, 0);
1158
- const ratios = numbers.map(number => number / total);
1186
+ const ratios = numbers.map((number) => number / total);
1159
1187
  const percentages = {};
1160
1188
  ratios.pop();
1161
1189
  ratios.forEach((ratio, index) => {
1162
1190
  const percentage = ratio * 100;
1163
1191
  percentages[numberNames[index]] = percentage;
1164
1192
  });
1165
- const lowestPercentage = 1 / Math.pow(10, maxPrecisionHint) * 100;
1193
+ const lowestPercentage = (1 / Math.pow(10, maxPrecisionHint)) * 100;
1166
1194
  let precision = 0;
1167
- Object.keys(percentages).forEach(name => {
1195
+ Object.keys(percentages).forEach((name) => {
1168
1196
  const percentage = percentages[name];
1169
1197
  if (percentage < lowestPercentage) {
1170
1198
  // check the amout of meaningful decimals
@@ -1177,33 +1205,36 @@ const distributePercentages = (namedNumbers, {
1177
1205
  }
1178
1206
  });
1179
1207
  let remainingPercentage = 100;
1180
- Object.keys(percentages).forEach(name => {
1208
+
1209
+ Object.keys(percentages).forEach((name) => {
1181
1210
  const percentage = percentages[name];
1182
1211
  const percentageAllocated = setRoundedPrecision(percentage, {
1183
- decimals: precision
1212
+ decimals: precision,
1184
1213
  });
1185
1214
  remainingPercentage -= percentageAllocated;
1186
1215
  percentages[name] = percentageAllocated;
1187
1216
  });
1188
1217
  const lastName = numberNames[numberNames.length - 1];
1189
1218
  percentages[lastName] = setRoundedPrecision(remainingPercentage, {
1190
- decimals: precision
1219
+ decimals: precision,
1191
1220
  });
1192
1221
  return percentages;
1193
1222
  };
1194
1223
 
1195
- const formatDefault = v => v;
1224
+ const formatDefault = (v) => v;
1225
+
1196
1226
  const generateContentFrame = ({
1197
1227
  content,
1198
1228
  line,
1199
1229
  column,
1230
+
1200
1231
  linesAbove = 3,
1201
1232
  linesBelow = 0,
1202
1233
  lineMaxWidth = 120,
1203
1234
  lineNumbersOnTheLeft = true,
1204
1235
  lineMarker = true,
1205
1236
  columnMarker = true,
1206
- format = formatDefault
1237
+ format = formatDefault,
1207
1238
  } = {}) => {
1208
1239
  const lineStrings = content.split(/\r?\n/);
1209
1240
  if (line === 0) line = 1;
@@ -1212,6 +1243,7 @@ const generateContentFrame = ({
1212
1243
  column = 1;
1213
1244
  }
1214
1245
  if (column === 0) column = 1;
1246
+
1215
1247
  let lineStartIndex = line - 1 - linesAbove;
1216
1248
  if (lineStartIndex < 0) {
1217
1249
  lineStartIndex = 0;
@@ -1228,6 +1260,7 @@ const generateContentFrame = ({
1228
1260
  lineMarker = false; // useless because last line
1229
1261
  }
1230
1262
  let lineIndex = lineStartIndex;
1263
+
1231
1264
  let columnsBefore;
1232
1265
  let columnsAfter;
1233
1266
  if (column > lineMaxWidth) {
@@ -1238,6 +1271,7 @@ const generateContentFrame = ({
1238
1271
  columnsAfter = lineMaxWidth;
1239
1272
  }
1240
1273
  let columnMarkerIndex = column - 1 - columnsBefore;
1274
+
1241
1275
  let source = "";
1242
1276
  while (lineIndex <= lineEndIndex) {
1243
1277
  const lineString = lineStrings[lineIndex];
@@ -1245,18 +1279,19 @@ const generateContentFrame = ({
1245
1279
  const isLastLine = lineIndex === lineEndIndex;
1246
1280
  const isMainLine = lineNumber === line;
1247
1281
  lineIndex++;
1282
+
1248
1283
  {
1249
1284
  if (lineMarker) {
1250
1285
  if (isMainLine) {
1251
- source += "".concat(format(">", "marker_line"), " ");
1286
+ source += `${format(">", "marker_line")} `;
1252
1287
  } else {
1253
1288
  source += " ";
1254
1289
  }
1255
1290
  }
1256
1291
  if (lineNumbersOnTheLeft) {
1257
1292
  // fill with spaces to ensure if line moves from 7,8,9 to 10 the display is still great
1258
- const asideSource = "".concat(fillLeft(lineNumber, lineEndIndex + 1), " |");
1259
- source += "".concat(format(asideSource, "line_number_aside"), " ");
1293
+ const asideSource = `${fillLeft(lineNumber, lineEndIndex + 1)} |`;
1294
+ source += `${format(asideSource, "line_number_aside")} `;
1260
1295
  }
1261
1296
  }
1262
1297
  {
@@ -1265,17 +1300,18 @@ const generateContentFrame = ({
1265
1300
  end: columnsAfter,
1266
1301
  prefix: "…",
1267
1302
  suffix: "…",
1268
- format
1303
+ format,
1269
1304
  });
1270
1305
  }
1271
1306
  {
1272
1307
  if (columnMarker && isMainLine) {
1273
- source += "\n";
1308
+ source += `\n`;
1274
1309
  if (lineMarker) {
1275
1310
  source += " ";
1276
1311
  }
1277
1312
  if (lineNumbersOnTheLeft) {
1278
- const asideSpaces = "".concat(fillLeft(lineNumber, lineEndIndex + 1), " | ").length;
1313
+ const asideSpaces = `${fillLeft(lineNumber, lineEndIndex + 1)} | `
1314
+ .length;
1279
1315
  source += " ".repeat(asideSpaces);
1280
1316
  }
1281
1317
  source += " ".repeat(columnMarkerIndex);
@@ -1288,24 +1324,23 @@ const generateContentFrame = ({
1288
1324
  }
1289
1325
  return source;
1290
1326
  };
1291
- const truncateLine = (line, {
1292
- start,
1293
- end,
1294
- prefix,
1295
- suffix,
1296
- format
1297
- }) => {
1327
+
1328
+ const truncateLine = (line, { start, end, prefix, suffix, format }) => {
1298
1329
  const lastIndex = line.length;
1330
+
1299
1331
  if (line.length === 0) {
1300
1332
  // don't show any ellipsis if the line is empty
1301
1333
  // because it's not truncated in that case
1302
1334
  return "";
1303
1335
  }
1336
+
1304
1337
  const startTruncated = start > 0;
1305
1338
  const endTruncated = lastIndex > end;
1339
+
1306
1340
  let from = startTruncated ? start + prefix.length : start;
1307
1341
  let to = endTruncated ? end - suffix.length : end;
1308
1342
  if (to > lastIndex) to = lastIndex;
1343
+
1309
1344
  if (start >= lastIndex || from === to) {
1310
1345
  return "";
1311
1346
  }
@@ -1318,16 +1353,20 @@ const truncateLine = (line, {
1318
1353
  return "";
1319
1354
  }
1320
1355
  if (startTruncated && endTruncated) {
1321
- return "".concat(format(prefix, "marker_overflow_left")).concat(result).concat(format(suffix, "marker_overflow_right"));
1356
+ return `${format(prefix, "marker_overflow_left")}${result}${format(
1357
+ suffix,
1358
+ "marker_overflow_right",
1359
+ )}`;
1322
1360
  }
1323
1361
  if (startTruncated) {
1324
- return "".concat(format(prefix, "marker_overflow_left")).concat(result);
1362
+ return `${format(prefix, "marker_overflow_left")}${result}`;
1325
1363
  }
1326
1364
  if (endTruncated) {
1327
- return "".concat(result).concat(format(suffix, "marker_overflow_right"));
1365
+ return `${result}${format(suffix, "marker_overflow_right")}`;
1328
1366
  }
1329
1367
  return result;
1330
1368
  };
1369
+
1331
1370
  const fillLeft = (value, biggestValue, char = " ") => {
1332
1371
  const width = String(value).length;
1333
1372
  const biggestWidth = String(biggestValue).length;
@@ -1344,8 +1383,9 @@ const createCallOrderer = () => {
1344
1383
  const queue = [];
1345
1384
  const callWhenPreviousExecutionAreDone = (executionIndex, callback) => {
1346
1385
  if (queue[executionIndex]) {
1347
- throw new Error("".concat(executionIndex, " already used"));
1386
+ throw new Error(`${executionIndex} already used`);
1348
1387
  }
1388
+
1349
1389
  let allBeforeAreDone = true;
1350
1390
  if (executionIndex > 0) {
1351
1391
  let beforeIndex = executionIndex - 1;
@@ -1379,26 +1419,43 @@ const createCallOrderer = () => {
1379
1419
  return callWhenPreviousExecutionAreDone;
1380
1420
  };
1381
1421
 
1382
- const errorToMarkdown = error => {
1383
- const errorIsAPrimitive = error === null || typeof error !== "object" && typeof error !== "function";
1422
+ const errorToMarkdown = (error) => {
1423
+ const errorIsAPrimitive =
1424
+ error === null ||
1425
+ (typeof error !== "object" && typeof error !== "function");
1426
+
1384
1427
  if (errorIsAPrimitive) {
1385
- return "```js\n".concat(error, "\n```");
1428
+ return `\`\`\`js
1429
+ ${error}
1430
+ \`\`\``;
1386
1431
  }
1387
- return "```\n".concat(error.stack, "\n```");
1432
+ return `\`\`\`
1433
+ ${error.stack}
1434
+ \`\`\``;
1388
1435
  };
1389
1436
 
1390
- const errorToHTML = error => {
1391
- const errorIsAPrimitive = error === null || typeof error !== "object" && typeof error !== "function";
1437
+ const errorToHTML = (error) => {
1438
+ const errorIsAPrimitive =
1439
+ error === null ||
1440
+ (typeof error !== "object" && typeof error !== "function");
1441
+
1392
1442
  if (errorIsAPrimitive) {
1393
1443
  if (typeof error === "string") {
1394
- return "<pre>".concat(escapeHtml(error), "</pre>");
1444
+ return `<pre>${escapeHtml(error)}</pre>`;
1395
1445
  }
1396
- return "<pre>".concat(JSON.stringify(error, null, " "), "</pre>");
1446
+ return `<pre>${JSON.stringify(error, null, " ")}</pre>`;
1397
1447
  }
1398
- return "<pre>".concat(escapeHtml(error.stack), "</pre>");
1448
+ return `<pre>${escapeHtml(error.stack)}</pre>`;
1399
1449
  };
1400
- const escapeHtml = string => {
1401
- return string.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
1450
+
1451
+ const escapeHtml = (string) => {
1452
+ return string
1453
+ .replace(/&/g, "&amp;")
1454
+ .replace(/</g, "&lt;")
1455
+ .replace(/>/g, "&gt;")
1456
+ .replace(/"/g, "&quot;")
1457
+ .replace(/'/g, "&#039;");
1402
1458
  };
1403
1459
 
1404
- export { ANSI, UNICODE, createCallOrderer, createDetailedMessage, distributePercentages, errorToHTML, errorToMarkdown, generateContentFrame, humanize, humanizeDuration, humanizeEllapsedTime, humanizeFileSize, humanizeMemory, humanizeMethodSymbol };
1460
+ export { ANSI, UNICODE, createCallOrderer, createDetailedMessage, distributePercentages, errorToHTML, errorToMarkdown, generateContentFrame, humanize, humanizeDuration, humanizeEllapsedTime, humanizeFileSize, humanizeMemory, humanizeMethodSymbol, preNewLineAndIndentation, prefixFirstAndIndentRemainingLines, wrapNewLineAndIndentation };
1461
+ //# sourceMappingURL=jsenv_humanize_browser.js.map