Files
lead-scraper/lib/utils/csv.ts
Timo Uttenweiler facf8c9f69 Initial commit: LeadFlow lead generation platform
Full-stack Next.js 16 app with three scraping pipelines:
- AirScale CSV → Anymailfinder Bulk Decision Maker search
- LinkedIn Sales Navigator → Vayne → Anymailfinder email enrichment
- Apify Google SERP → domain extraction → Anymailfinder bulk enrichment

Includes Docker multi-stage build + docker-compose for Coolify deployment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 11:21:11 +01:00

54 lines
1.5 KiB
TypeScript

import Papa from "papaparse";
import * as XLSX from "xlsx";
export function parseCSV(content: string): { data: Record<string, string>[]; headers: string[] } {
const result = Papa.parse<Record<string, string>>(content, {
header: true,
skipEmptyLines: true,
transformHeader: (h) => h.trim(),
});
return {
data: result.data,
headers: result.meta.fields || [],
};
}
export function detectDomainColumn(headers: string[]): string | null {
const candidates = ["domain", "website", "url", "web", "site", "homepage", "company_domain", "company_url"];
for (const candidate of candidates) {
const found = headers.find(h => h.toLowerCase().includes(candidate));
if (found) return found;
}
return null;
}
export interface ExportRow {
company_name?: string;
domain?: string;
contact_name?: string;
contact_title?: string;
email?: string;
confidence_score?: number | string;
source_tab?: string;
job_id?: string;
found_at?: string;
}
export function exportToCSV(rows: ExportRow[], filename: string): void {
const csv = Papa.unparse(rows);
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
link.click();
URL.revokeObjectURL(url);
}
export function exportToExcel(rows: ExportRow[], filename: string): void {
const ws = XLSX.utils.json_to_sheet(rows);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Leads");
XLSX.writeFile(wb, filename);
}