File

src/orders/ingestion/parsers/csv.parser.ts

Index

Methods

Methods

parse
parse(buffer: Buffer)
Parameters :
Name Type Optional
buffer Buffer No
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: [],
      };
    }
  }
}

results matching ""

    No results matching ""