Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

745 B
Raw Blame
import { ensureUniqueTitle } from "@/lib/resumeCopyTitle";

const MAX_TITLE_LENGTH = 100;

// Reuses the resume-copy uniquifier: the " (2)" / " (3)" convention and the
// 100-char fit are identical for both document types.
export const buildCoverLetterTitle = (
  jobTitle: string,
  companyName: string,
  takenTitles: string[],
): string => {
  const title = jobTitle.trim();
  const company = companyName.trim();
  // Trim the job title rather than the whole string so the company survives.
  const room = MAX_TITLE_LENGTH - (company ? company.length + 3 : 0);
  const base = company
    ? `${title.slice(0, Math.max(room, 0)).trimEnd()} - ${company}`
    : title.slice(0, MAX_TITLE_LENGTH);
  return ensureUniqueTitle(base, takenTitles);
};