update: change the mechanism that quoted GUIDs in pretty table format to a generic one and added IPv4 addresses to prettyfied type list.
This commit is contained in:
@@ -215,15 +215,14 @@ export function renderOutput(
|
|||||||
console.log(toMarkdownTable(
|
console.log(toMarkdownTable(
|
||||||
output,
|
output,
|
||||||
outputFormat === "alignedtable" || outputFormat === "prettytable",
|
outputFormat === "alignedtable" || outputFormat === "prettytable",
|
||||||
outputFormat === "prettytable",
|
|
||||||
headerSpec,
|
headerSpec,
|
||||||
));
|
));
|
||||||
} else if (outputFormat === "alignedtable") {
|
} else if (outputFormat === "alignedtable") {
|
||||||
console.log(toMarkdownTable(output, true, false, headerSpec));
|
console.log(toMarkdownTable(output, true, headerSpec));
|
||||||
} else if (outputFormat === "prettytable") {
|
} else if (outputFormat === "prettytable") {
|
||||||
console.log(toMarkdownTable(output, true, true, headerSpec));
|
console.log(toMarkdownTable(output, true, headerSpec));
|
||||||
} else if (outputFormat === "table") {
|
} else if (outputFormat === "table") {
|
||||||
console.log(toMarkdownTable(output, false, false, headerSpec));
|
console.log(toMarkdownTable(output, false, headerSpec));
|
||||||
} else {
|
} else {
|
||||||
console.log(JSON.stringify(output, null, 2));
|
console.log(JSON.stringify(output, null, 2));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,25 @@ function formatCell(value: unknown): string {
|
|||||||
return text.replaceAll("|", "\\|").replaceAll("\n", "<br>");
|
return text.replaceAll("|", "\\|").replaceAll("\n", "<br>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inlineCodePredicates = [
|
||||||
|
(value: Scalar): boolean => isGuid(value),
|
||||||
|
(value: Scalar): boolean =>
|
||||||
|
typeof value === "string"
|
||||||
|
&& /^(?:\d{1,3}\.){3}\d{1,3}(?:\/(?:\d{1,2}|(?:\d{1,3}\.){3}\d{1,3}))?$/.test(value),
|
||||||
|
];
|
||||||
|
|
||||||
|
function renderCell(raw: Scalar): string {
|
||||||
|
const text = formatCell(raw);
|
||||||
|
|
||||||
|
for (const predicate of inlineCodePredicates) {
|
||||||
|
if (predicate(raw)) {
|
||||||
|
return `\`${text}\``;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
function isGuid(value: unknown): value is string {
|
function isGuid(value: unknown): value is string {
|
||||||
return typeof value === "string"
|
return typeof value === "string"
|
||||||
&& /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
&& /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
||||||
@@ -88,7 +107,6 @@ function getScalarRowsAndHeaders(value: unknown): { headers: string[]; rows: Sca
|
|||||||
export function toMarkdownTable(
|
export function toMarkdownTable(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
pretty = false,
|
pretty = false,
|
||||||
quoteGuids = false,
|
|
||||||
headerSpec: HeaderSpec = { mode: "default" },
|
headerSpec: HeaderSpec = { mode: "default" },
|
||||||
): string {
|
): string {
|
||||||
const { headers, rows } = getScalarRowsAndHeaders(value);
|
const { headers, rows } = getScalarRowsAndHeaders(value);
|
||||||
@@ -104,11 +122,6 @@ export function toMarkdownTable(
|
|||||||
return { key, label };
|
return { key, label };
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderCell = (raw: Scalar): string => {
|
|
||||||
const text = formatCell(raw);
|
|
||||||
return quoteGuids && isGuid(raw) ? `\`${text}\`` : text;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!pretty) {
|
if (!pretty) {
|
||||||
const headerLine = `| ${headerDefinitions.map((h) => h.label).join(" | ")} |`;
|
const headerLine = `| ${headerDefinitions.map((h) => h.label).join(" | ")} |`;
|
||||||
const separatorLine = `| ${headerDefinitions.map(() => "---").join(" | ")} |`;
|
const separatorLine = `| ${headerDefinitions.map(() => "---").join(" | ")} |`;
|
||||||
|
|||||||
Reference in New Issue
Block a user