Raw match results array from storage.
Array of normalized match results safe for statistics visualization.
export function normalizeMatchResults(
results: unknown,
): NormalizedMatchForStats[] {
if (!Array.isArray(results)) {
return [];
}
const normalized: NormalizedMatchForStats[] = [];
for (const entry of results) {
if (typeof entry !== "object" || entry === null) {
continue;
}
const result = entry as Record<string, unknown>;
// Extract kenmeiManga - skip if invalid
const kenmeiMangaRaw = result.kenmeiManga;
const kenmeiManga = extractKenmeiManga(kenmeiMangaRaw);
if (!kenmeiManga) {
continue;
}
// Parse other fields
const matchDate = parseMatchDate(result.matchDate);
const selectedMatch = buildSelectedMatch(result.selectedMatch);
const status = parseStatus(result.status);
// Build normalized result with minimal type
normalized.push({
kenmeiManga,
anilistMatches: Array.isArray(result.anilistMatches)
? (result.anilistMatches as MangaMatch[] | undefined)
: undefined,
selectedMatch,
status,
matchDate,
});
}
return normalized;
}
Normalizes match results from storage into optimized statistics format; safely validates and skips invalid entries.