Skip to content

Commit

Permalink
chore: use for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
matyax committed Aug 23, 2024
1 parent da26d20 commit afd04d2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/services/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,25 @@ export function extractParserAndFieldsFromDataFrame(data: DataFrame) {
);

const types: ExtractedFieldsType[] = [];

const linesField = data.fields.find((f) => f.name === 'Line' || f.name === 'body');
linesField?.values.forEach((value: string) => {

if (!linesField) {
return result;
}

for (let i = 0; i < linesField.values.length; i++) {
if (types.length === 2) {
return;
break;
}
const line = value.trim();
const line = linesField.values[i].trim();
if (line.startsWith('{') && line.endsWith('}')) {
if (!types.includes('json')) {
types.push('json');
}
} else if (!types.includes('logfmt')) {
types.push('logfmt');
}
});
}

result.type = types.length === 1 ? types[0] : 'mixed';

Expand Down

0 comments on commit afd04d2

Please sign in to comment.