( obj: any, format: 'json' | 'ts', indentationLevel: number = 1, isArrayElement: boolean = false, )
| 85 | // stays compact, while standalone objects assigned to a property (e.g. `compiler.options`) keep |
| 86 | // their values expanded one per line. |
| 87 | function stringify( |
| 88 | obj: any, |
| 89 | format: 'json' | 'ts', |
| 90 | indentationLevel: number = 1, |
| 91 | isArrayElement: boolean = false, |
| 92 | ): string { |
| 93 | if (typeof obj === 'string') return formatString(obj, format); |
| 94 | |
| 95 | // Numbers, booleans and null are represented identically in JSON and TS |
| 96 | if (obj === null || typeof obj === 'number' || typeof obj === 'boolean') { |
| 97 | return JSON.stringify(obj); |
| 98 | } |
| 99 | |
| 100 | if (Array.isArray(obj)) return formatArray(obj, format, indentationLevel, isArrayElement); |
| 101 | |
| 102 | if (typeof obj === 'object') return formatObject(obj, format, indentationLevel, isArrayElement); |
| 103 | |
| 104 | throw new Error(`Unsupported type: ${typeof obj}`); |
| 105 | } |
| 106 | |
| 107 | function formatString(value: string, format: 'json' | 'ts'): string { |
| 108 | // JSON strings use standard double-quoted escaping |
no test coverage detected