MCPcopy Index your code
hub / github.com/MiniMax-AI/cli / formatKeyValue

Function formatKeyValue

src/output/text.ts:21–45  ·  view source on GitHub ↗
(obj: Record<string, unknown>, indent = 0)

Source from the content-addressed store, hash-verified

19}
20
21export function formatKeyValue(obj: Record<string, unknown>, indent = 0): string {
22 const prefix = ' '.repeat(indent);
23 const lines: string[] = [];
24
25 for (const [key, value] of Object.entries(obj)) {
26 if (value === null || value === undefined) continue;
27 if (Array.isArray(value)) {
28 lines.push(`${prefix}${key}:`);
29 for (const item of value) {
30 if (typeof item === 'object' && item !== null) {
31 lines.push(`${prefix} - ${formatKeyValue(item as Record<string, unknown>, indent + 4).trimStart()}`);
32 } else {
33 lines.push(`${prefix} - ${String(item)}`);
34 }
35 }
36 } else if (typeof value === 'object') {
37 lines.push(`${prefix}${key}:`);
38 lines.push(formatKeyValue(value as Record<string, unknown>, indent + 2));
39 } else {
40 lines.push(`${prefix}${key}: ${String(value)}`);
41 }
42 }
43
44 return lines.join('\n');
45}
46
47export function formatTable(rows: Record<string, unknown>[]): string {
48 if (rows.length === 0) return '(empty)';

Callers 1

formatTextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected