Array of manga items to normalize.
Array of normalized manga items with guaranteed IDs.
export function normalizeMangaItems(
manga: KenmeiMangaItem[],
): NormalizedMangaItem[] {
console.debug(`[MangaImport] Normalizing ${manga.length} manga items`);
const normalized = manga.map((item, idx) => ({
id: (item as { id?: string | number }).id ?? `import_${Date.now()}_${idx}`,
title: item.title,
status: item.status,
score: item.score ?? 0,
chaptersRead: item.chaptersRead ?? 0,
volumesRead: item.volumesRead ?? 0,
notes: item.notes ?? "",
createdAt: item.createdAt,
updatedAt: item.updatedAt,
lastReadAt: item.lastReadAt,
}));
console.debug(
`[MangaImport] Successfully normalized ${normalized.length} items`,
);
return normalized;
}
Normalizes manga items by ensuring unique IDs and filling in default values for optional fields.