MCPcopy
hub / github.com/MiniMax-AI/cli / formatText

Function formatText

src/output/text.ts:1–19  ·  view source on GitHub ↗
(data: unknown)

Source from the content-addressed store, hash-verified

1export function formatText(data: unknown): string {
2 if (data === null || data === undefined) return '';
3 if (typeof data === 'string') return data;
4 if (typeof data === 'number' || typeof data === 'boolean') return String(data);
5
6 if (Array.isArray(data)) {
7 if (data.length === 0) return '(empty)';
8 if (typeof data[0] === 'object' && data[0] !== null) {
9 return formatTable(data as Record<string, unknown>[]);
10 }
11 return data.map(String).join('\n');
12 }
13
14 if (typeof data === 'object') {
15 return formatKeyValue(data as Record<string, unknown>);
16 }
17
18 return String(data);
19}
20
21export function formatKeyValue(obj: Record<string, unknown>, indent = 0): string {
22 const prefix = ' '.repeat(indent);

Callers 1

formatOutputFunction · 0.90

Calls 2

formatTableFunction · 0.85
formatKeyValueFunction · 0.85

Tested by

no test coverage detected