Raw manga entry to normalize (may have missing/optional fields).
Normalization options including defaultStatus.
Fully normalized KenmeiManga entry with all required fields populated.
export function normalizeKenmeiManga(
entry: Partial<KenmeiManga>,
options: {
defaultStatus?: KenmeiStatus;
} = {},
): KenmeiManga {
const { defaultStatus = "plan_to_read" } = options;
const now = new Date().toISOString();
// Normalize status: validate and apply default if missing/invalid
const status =
entry.status && isValidStatus(entry.status) ? entry.status : defaultStatus;
// Normalize numeric fields with defaults
const chaptersRead =
typeof entry.chaptersRead === "number" ? entry.chaptersRead : 0;
const volumesRead =
typeof entry.volumesRead === "number" ? entry.volumesRead : undefined;
const score = typeof entry.score === "number" ? entry.score : 0;
// Normalize timestamp fields
const createdAt = entry.createdAt ?? now;
const updatedAt = entry.updatedAt ?? now;
return {
id: entry.id ?? 0,
title: entry.title ?? "Unknown Title",
status,
score,
url: entry.url ?? "",
coverUrl: entry.coverUrl,
chaptersRead: chaptersRead,
totalChapters: entry.totalChapters,
volumesRead: volumesRead,
totalVolumes: entry.totalVolumes,
notes: entry.notes,
lastReadAt: entry.lastReadAt,
createdAt: createdAt,
updatedAt: updatedAt,
author: entry.author,
alternativeTitles: entry.alternativeTitles,
anilistId: entry.anilistId,
};
}
Normalize a Kenmei manga entry, applying validation and default values.
This is the single source of truth for manga normalization, used by both JSON and CSV parsing paths. Ensures consistent field handling, status validation, and default application across all import formats.