src/orders/ingestion/parsers/csv.parser.ts
Methods |
| parse | ||||||
parse(buffer: Buffer)
|
||||||
|
Defined in src/orders/ingestion/parsers/csv.parser.ts:4
|
||||||
|
Parameters :
Returns :
literal type
|
import { parse } from 'csv-parse/sync';
export class CsvParser {
parse(buffer: Buffer): { rawText: string; rows: any[][] } {
const content = buffer.toString('utf-8');
// Try to parse as structured CSV first
try {
const records: string[][] = parse(content, {
relax_column_count: true,
skip_empty_lines: true,
trim: true,
});
return {
rawText: `=== CSV File (${records.length} rows) ===\n${content}`,
rows: records,
};
} catch {
// If CSV parsing fails, just pass the raw text through
// Claude can handle messy data
return {
rawText: `=== CSV File (raw) ===\n${content}`,
rows: [],
};
}
}
}