Kenmei manga entry.
Matching AniList manga entry.
Processing options.
Prepared entry ready for AniList update.
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 progress = manga.chapters_read ?? 0;
const hasVolumeData =
manga.volumes_read !== undefined && manga.volumes_read !== null;
// If preferVolumes and volume data exists, expose progressVolumes else undefined
const progressVolumes =
processOptions.preferVolumes && hasVolumeData
? manga.volumes_read
: (manga.volumes_read ?? 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 Kenmei manga entry for AniList synchronization.