| 113 | } |
| 114 | |
| 115 | function formatArray( |
| 116 | array: readonly any[], |
| 117 | format: 'json' | 'ts', |
| 118 | indentationLevel: number, |
| 119 | isArrayElement: boolean, |
| 120 | ): string { |
| 121 | if (array.length === 0) return '[]'; |
| 122 | |
| 123 | const items = array.map((item) => stringify(item, format, indentationLevel + 1, true)); |
| 124 | |
| 125 | if (isArrayElement && canInline(array)) return `[${items.join(', ')}]`; |
| 126 | |
| 127 | const lines = items.map((item) => `${indent(indentationLevel)}${item}`).join(',\n'); |
| 128 | const trailingComma = format === 'ts' ? ',' : ''; |
| 129 | return `[\n${lines}${trailingComma}\n${indent(indentationLevel - 1)}]`; |
| 130 | } |
| 131 | |
| 132 | function formatObject( |
| 133 | obj: any, |