Kenmei manga entry to prepare.
Matched AniList manga entry with ID.
Optional processing configuration.
AniList-formatted entry ready for sync with mediaId, status, progress, and optional score.
export function prepareEntryForSync(
manga: KenmeiManga,
anilistMatch: AniListManga,
options: Partial<ProcessOptions> = {},
): {
mediaId: number;
status: string;
progress: number;
score?: number;
progressVolumes?: number;
} {
const processOptions = { ...DEFAULT_PROCESS_OPTIONS, ...options };
// Map the status
const status = mapKenmeiToAniListStatus(
manga.status,
processOptions.statusMapping,
);
// Determine progress (chapters vs volumes)
// Use guard clauses and prefer explicit undefined over nullish values
const hasVolumeData =
manga.volumesRead !== undefined && manga.volumesRead !== null;
// If preferVolumes and volume data exists, use volumes only; otherwise use chapters
let progress: number;
let progressVolumes: number | undefined;
if (processOptions.preferVolumes && hasVolumeData) {
// When preferring volumes, set progress to 0 and expose only progressVolumes
progress = 0;
progressVolumes = manga.volumesRead;
} else {
// Default: use chapters for progress, optionally expose volumes
progress = manga.chaptersRead ?? 0;
progressVolumes = hasVolumeData ? manga.volumesRead : undefined;
}
// Normalize score if needed (Kenmei uses 1-10, AniList uses 1-100 or 1-10 depending on settings)
let rawScore = manga.score ?? undefined;
if (
processOptions.normalizeScores &&
typeof rawScore === "number" &&
rawScore > 0
) {
// We'll assume AniList is using the 100-point scale
rawScore = Math.round(rawScore * 10);
}
const score =
typeof rawScore === "number" && rawScore > 0 ? rawScore : undefined;
return {
mediaId: anilistMatch.id,
status,
progress,
progressVolumes,
score,
};
}
Prepare a Kenmei manga entry for AniList synchronization, mapping status and scores.