export function parseKeywordSet(csv: string): Set<string> {
  return new Set(
    csv
      .split(',')
      .map((s) => s.trim().toLowerCase())
      .filter(Boolean),
  );
}

export function mergeKeywordCSV(current: string, addition: string): string {
  const set = parseKeywordSet(current);
  addition.split(',').forEach((k) => {
    const kw = k.trim().toLowerCase();
    if (kw) set.add(kw);
  });
  return Array.from(set).join(', ');
}

export function countKeywords(csv: string): number {
  return parseKeywordSet(csv).size;
}
