|
1 | 1 | import chalk from 'chalk'; |
2 | 2 |
|
3 | | -import { IOutputWriter } from '../../types/rendering'; |
| 3 | +import { IOutputWriter, OutputFormat } from '../../types/rendering'; |
4 | 4 | import { formatJson } from '../parsers/json.parser'; |
5 | 5 | import { isNullOrUndefined, isObject } from '../helpers/type.helper'; |
6 | 6 |
|
@@ -56,15 +56,15 @@ export class ConsoleOutputWriter implements IOutputWriter { |
56 | 56 | /** |
57 | 57 | * Writes structured data in the specified format. |
58 | 58 | */ |
59 | | - writeFormatted(data: unknown, format: 'json' | 'csv' | 'table'): void { |
| 59 | + writeFormatted(data: unknown, format: OutputFormat): void { |
60 | 60 | switch (format) { |
61 | | - case 'json': |
| 61 | + case OutputFormat.JSON: |
62 | 62 | console.log(formatJson(data)); |
63 | 63 | break; |
64 | | - case 'csv': |
| 64 | + case OutputFormat.CSV: |
65 | 65 | this.writeCsv(data); |
66 | 66 | break; |
67 | | - case 'table': |
| 67 | + case OutputFormat.TABLE: |
68 | 68 | this.writeTable(data); |
69 | 69 | break; |
70 | 70 | default: |
@@ -118,11 +118,8 @@ export class ConsoleOutputWriter implements IOutputWriter { |
118 | 118 | // Write data rows |
119 | 119 | data.forEach((item) => { |
120 | 120 | if (isObject(item)) { |
121 | | - // eslint-disable-next-line security/detect-object-injection |
122 | 121 | const values = headers.map((header) => { |
123 | | - const value = Object.prototype.hasOwnProperty.call(item, header) |
124 | | - ? (item as Record<string, unknown>)[header] |
125 | | - : null; |
| 122 | + const value = Reflect.get(item, header) ?? null; |
126 | 123 | // Escape quotes and wrap in quotes if contains comma |
127 | 124 | const stringValue = String(value ?? ''); |
128 | 125 | return stringValue.includes(',') ? `"${stringValue.replace(/"/g, '""')}"` : stringValue; |
|
0 commit comments