import { parse } from 'csv-parse/browser/esm/sync'; import type { CardData } from '../types'; /** * 全局缓存已加载的 CSV 内容 */ const csvCache = new Map(); /** * 加载 CSV 文件 */ export async function loadCSV(path: string): Promise { if (csvCache.has(path)) { return csvCache.get(path)!; } const response = await fetch(path); const content = await response.text(); const records = parse(content, { columns: true, comment: '#', trim: true, skipEmptyLines: true }); const result = records as CardData[]; csvCache.set(path, result); return result; }