mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 14:57:28 +00:00
22 lines
651 B
TypeScript
22 lines
651 B
TypeScript
export type OutputFormat = "json" | "table" | "markdown";
|
|
|
|
export function print(data: unknown, format: OutputFormat) {
|
|
if (format === "json") {
|
|
console.log(JSON.stringify(data, null, 2));
|
|
return;
|
|
}
|
|
|
|
if (format === "markdown") {
|
|
if (Array.isArray(data)) {
|
|
for (const item of data) {
|
|
console.log(`- ${Object.entries(item as Record<string, unknown>).map(([key, value]) => `**${key}:** ${String(value)}`).join(", ")}`);
|
|
}
|
|
return;
|
|
}
|
|
|
|
console.log(Object.entries(data as Record<string, unknown>).map(([key, value]) => `**${key}:** ${String(value)}`).join("\n"));
|
|
return;
|
|
}
|
|
|
|
console.table(data);
|
|
}
|