@jsenv/humanize 1.4.0 → 1.5.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.
|
@@ -1379,4 +1379,26 @@ const createCallOrderer = () => {
|
|
|
1379
1379
|
return callWhenPreviousExecutionAreDone;
|
|
1380
1380
|
};
|
|
1381
1381
|
|
|
1382
|
-
|
|
1382
|
+
const errorToMarkdown = error => {
|
|
1383
|
+
const errorIsAPrimitive = error === null || typeof error !== "object" && typeof error !== "function";
|
|
1384
|
+
if (errorIsAPrimitive) {
|
|
1385
|
+
return "```js\n".concat(error, "\n```");
|
|
1386
|
+
}
|
|
1387
|
+
return "```\n".concat(error.stack, "\n```");
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
const errorToHTML = error => {
|
|
1391
|
+
const errorIsAPrimitive = error === null || typeof error !== "object" && typeof error !== "function";
|
|
1392
|
+
if (errorIsAPrimitive) {
|
|
1393
|
+
if (typeof error === "string") {
|
|
1394
|
+
return "<pre>".concat(escapeHtml(error), "</pre>");
|
|
1395
|
+
}
|
|
1396
|
+
return "<pre>".concat(JSON.stringify(error, null, " "), "</pre>");
|
|
1397
|
+
}
|
|
1398
|
+
return "<pre>".concat(escapeHtml(error.stack), "</pre>");
|
|
1399
|
+
};
|
|
1400
|
+
const escapeHtml = string => {
|
|
1401
|
+
return string.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
export { ANSI, UNICODE, createCallOrderer, createDetailedMessage, distributePercentages, errorToHTML, errorToMarkdown, generateContentFrame, humanize, humanizeDuration, humanizeEllapsedTime, humanizeFileSize, humanizeMemory, humanizeMethodSymbol };
|
|
@@ -1407,6 +1407,44 @@ const createCallOrderer = () => {
|
|
|
1407
1407
|
return callWhenPreviousExecutionAreDone;
|
|
1408
1408
|
};
|
|
1409
1409
|
|
|
1410
|
+
const errorToMarkdown = (error) => {
|
|
1411
|
+
const errorIsAPrimitive =
|
|
1412
|
+
error === null ||
|
|
1413
|
+
(typeof error !== "object" && typeof error !== "function");
|
|
1414
|
+
|
|
1415
|
+
if (errorIsAPrimitive) {
|
|
1416
|
+
return `\`\`\`js
|
|
1417
|
+
${error}
|
|
1418
|
+
\`\`\``;
|
|
1419
|
+
}
|
|
1420
|
+
return `\`\`\`
|
|
1421
|
+
${error.stack}
|
|
1422
|
+
\`\`\``;
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1425
|
+
const errorToHTML = (error) => {
|
|
1426
|
+
const errorIsAPrimitive =
|
|
1427
|
+
error === null ||
|
|
1428
|
+
(typeof error !== "object" && typeof error !== "function");
|
|
1429
|
+
|
|
1430
|
+
if (errorIsAPrimitive) {
|
|
1431
|
+
if (typeof error === "string") {
|
|
1432
|
+
return `<pre>${escapeHtml(error)}</pre>`;
|
|
1433
|
+
}
|
|
1434
|
+
return `<pre>${JSON.stringify(error, null, " ")}</pre>`;
|
|
1435
|
+
}
|
|
1436
|
+
return `<pre>${escapeHtml(error.stack)}</pre>`;
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
const escapeHtml = (string) => {
|
|
1440
|
+
return string
|
|
1441
|
+
.replace(/&/g, "&")
|
|
1442
|
+
.replace(/</g, "<")
|
|
1443
|
+
.replace(/>/g, ">")
|
|
1444
|
+
.replace(/"/g, """)
|
|
1445
|
+
.replace(/'/g, "'");
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1410
1448
|
const renderBigSection = (params) => {
|
|
1411
1449
|
return renderSection({
|
|
1412
1450
|
width: 45,
|
|
@@ -1964,4 +2002,4 @@ const createTaskLog = (
|
|
|
1964
2002
|
};
|
|
1965
2003
|
};
|
|
1966
2004
|
|
|
1967
|
-
export { ANSI, UNICODE, createCallOrderer, createDetailedMessage, createDynamicLog, createLogger, createTaskLog, distributePercentages, generateContentFrame, humanize, humanizeDuration, humanizeEllapsedTime, humanizeFileSize, humanizeMemory, humanizeMethodSymbol, renderBigSection, renderDetails, renderNamedSections, renderSection, startSpinner };
|
|
2005
|
+
export { ANSI, UNICODE, createCallOrderer, createDetailedMessage, createDynamicLog, createLogger, createTaskLog, distributePercentages, errorToHTML, errorToMarkdown, generateContentFrame, humanize, humanizeDuration, humanizeEllapsedTime, humanizeFileSize, humanizeMemory, humanizeMethodSymbol, renderBigSection, renderDetails, renderNamedSections, renderSection, startSpinner };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/humanize",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Generate messages meant to read by humans",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,9 @@
|
|
|
32
32
|
"/dist/",
|
|
33
33
|
"/src/"
|
|
34
34
|
],
|
|
35
|
-
"sideEffects":
|
|
35
|
+
"sideEffects": [
|
|
36
|
+
"./dist/node/jsenv_humanize_node_modules.js"
|
|
37
|
+
],
|
|
36
38
|
"scripts": {
|
|
37
39
|
"build": "node ./scripts/build.mjs",
|
|
38
40
|
"prepublishOnly": "npm run build"
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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/main_browser.js
CHANGED
|
@@ -9,3 +9,5 @@ export { humanizeFileSize, humanizeMemory } from "./byte/byte.js";
|
|
|
9
9
|
export { distributePercentages } from "./percentage/distribute_percentages.js";
|
|
10
10
|
export { generateContentFrame } from "./content_frame/content_frame.js";
|
|
11
11
|
export { createCallOrderer } from "./log/call_orderer.js";
|
|
12
|
+
export { errorToMarkdown } from "./error/error_to_markdown.js";
|
|
13
|
+
export { errorToHTML } from "./error/error_to_html.js";
|
package/src/main_node.js
CHANGED
|
@@ -12,6 +12,8 @@ export { humanizeFileSize, humanizeMemory } from "./byte/byte.js";
|
|
|
12
12
|
export { distributePercentages } from "./percentage/distribute_percentages.js";
|
|
13
13
|
export { generateContentFrame } from "./content_frame/content_frame.js";
|
|
14
14
|
export { createCallOrderer } from "./log/call_orderer.js";
|
|
15
|
+
export { errorToMarkdown } from "./error/error_to_markdown.js";
|
|
16
|
+
export { errorToHTML } from "./error/error_to_html.js";
|
|
15
17
|
|
|
16
18
|
// node only
|
|
17
19
|
export { renderSection, renderBigSection } from "./log/section.js";
|