(data: unknown, options?: { showEfficiencyHint?: boolean })
| 163 | * @see https://toonformat.dev/ |
| 164 | */ |
| 165 | export function outputToon(data: unknown, options?: { showEfficiencyHint?: boolean }): void { |
| 166 | const toonOutput = toonEncode(data) |
| 167 | console.log(toonOutput) |
| 168 | |
| 169 | // Show efficiency hint if enabled and not in quiet mode |
| 170 | if (options?.showEfficiencyHint && !currentConfig.quiet) { |
| 171 | // Pass pre-encoded toonOutput to avoid re-encoding |
| 172 | const { savingsPercent, toonRecommended } = analyzeToonEfficiency(data, toonOutput) |
| 173 | |
| 174 | if (!toonRecommended) { |
| 175 | const hint = |
| 176 | savingsPercent <= 0 |
| 177 | ? `Hint: JSON would be ${Math.abs(savingsPercent).toFixed(0)}% smaller for this data. ` + |
| 178 | 'Consider --output json for better compatibility.' |
| 179 | : `Hint: TOON only saves ${savingsPercent.toFixed(0)}% over JSON for this data. ` + |
| 180 | 'TOON works best with uniform arrays of objects (30-60% typical savings).' |
| 181 | |
| 182 | console.error(cliChalk.dim(hint)) |
| 183 | } |
| 184 | } |
| 185 | } |
no test coverage detected