Skip to content

Commit 8e5ce9d

Browse files
committed
feat: update writeFormatted method to use OutputFormat enum for better type safety
1 parent e17f55b commit 8e5ce9d

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/core/rendering/console-output.writer.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import chalk from 'chalk';
22

3-
import { IOutputWriter } from '../../types/rendering';
3+
import { IOutputWriter, OutputFormat } from '../../types/rendering';
44
import { formatJson } from '../parsers/json.parser';
55
import { isNullOrUndefined, isObject } from '../helpers/type.helper';
66

@@ -56,15 +56,15 @@ export class ConsoleOutputWriter implements IOutputWriter {
5656
/**
5757
* Writes structured data in the specified format.
5858
*/
59-
writeFormatted(data: unknown, format: 'json' | 'csv' | 'table'): void {
59+
writeFormatted(data: unknown, format: OutputFormat): void {
6060
switch (format) {
61-
case 'json':
61+
case OutputFormat.JSON:
6262
console.log(formatJson(data));
6363
break;
64-
case 'csv':
64+
case OutputFormat.CSV:
6565
this.writeCsv(data);
6666
break;
67-
case 'table':
67+
case OutputFormat.TABLE:
6868
this.writeTable(data);
6969
break;
7070
default:
@@ -118,11 +118,8 @@ export class ConsoleOutputWriter implements IOutputWriter {
118118
// Write data rows
119119
data.forEach((item) => {
120120
if (isObject(item)) {
121-
// eslint-disable-next-line security/detect-object-injection
122121
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;
126123
// Escape quotes and wrap in quotes if contains comma
127124
const stringValue = String(value ?? '');
128125
return stringValue.includes(',') ? `"${stringValue.replace(/"/g, '""')}"` : stringValue;

0 commit comments

Comments
 (0)