Files
lead-scraper/lib/utils/csv.ts
Timo Uttenweiler 115cdacd08 UI improvements: Leadspeicher, Maps enrichment, exports
- Rename LeadVault → Leadspeicher throughout (sidebar, topbar, page)
- SidePanel: full lead detail view with contact, source, tags (read-only), Google Maps link for address
- Tags: kontaktiert stored as tag (toggleable), favorit tag toggle
- Remove Status column, StatusBadge dropdown, Priority feature
- Remove Aktualisieren button from Leadspeicher
- Bulk actions: remove status dropdown
- Export: LeadVault Excel-only, clean columns, freeze row + autofilter
- Export dropdown: click-based (fix overflow-hidden clipping)
- ExportButtons: remove CSV, Excel only everywhere
- Maps page: post-search Anymailfinder enrichment button
- ProgressCard: "Suche läuft..." instead of "Warte auf Anymailfinder-Server..."
- Quick SERP renamed to "Schnell neue Suche"
- Results page: Excel export, always-enabled download button
- Anymailfinder: fix bulk field names, array-of-arrays format
- Apify: fix countryCode lowercase
- API: sourceTerm search, contacted/favorite tag filters

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

50 lines
1.4 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;
}
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);
}