Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

599 B
Raw Blame
import { parse, Parser } from 'csv-parse';

export function createCsvParser({ delimiter }: { delimiter: string }): CsvParser {
  let headers: string[] = [];
  const parser = parse({
    delimiter,
    bom: true,
    relax_column_count: true,
    group_columns_by_name: true,
    columns: (header: string[]) => {
      headers = header;
      return header;
    },
    skip_empty_lines: true,
    trim: true,
  });
  return { parser, getHeaders: () => headers };
}

export type CsvRow = Record<string, string | string[]>;

export type CsvParser = {
  parser: Parser;
  getHeaders: () => string[];
};