src / utils / block.ts
/* -------------------------------------------------------------------------- */
/* Structured log block helper */
/* -------------------------------------------------------------------------- */
/**
* Builds a titled multi-line block with uniform 2-space indented entries.
* Entries whose value is `undefined` or `null` are omitted.
* Returns `null` if no entries survive filtering (avoids emitting an empty title).
*/
export function formatBlock(title: string, entries: Array<[string, unknown]>): string | null {
const INDENT = " ";
const lines = entries
.filter(([, v]) => v !== undefined && v !== null)
.map(([k, v]) => `${INDENT}${k}: ${v}`);
if (lines.length === 0) return null;
return `${title}\n${lines.join("\n")}`;
}
src / utils / block.ts
/* -------------------------------------------------------------------------- */
/* Structured log block helper */
/* -------------------------------------------------------------------------- */
/**
* Builds a titled multi-line block with uniform 2-space indented entries.
* Entries whose value is `undefined` or `null` are omitted.
* Returns `null` if no entries survive filtering (avoids emitting an empty title).
*/
export function formatBlock(title: string, entries: Array<[string, unknown]>): string | null {
const INDENT = " ";
const lines = entries
.filter(([, v]) => v !== undefined && v !== null)
.map(([k, v]) => `${INDENT}${k}: ${v}`);
if (lines.length === 0) return null;
return `${title}\n${lines.join("\n")}`;
}