src/utils/games.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import config, { type Game } from "@/config";
const { games: GAMES } = config;
export function getGame(id: string) {
const game = GAMES.find((game) => game.universeId === id);
return game;
}
export function getGames(ids: string[]) {
return GAMES.filter((game) => ids.includes(game.id));
}
export function parseIncludedGames(games: string | null | undefined): Game[] {
if (!games) return GAMES;
const parsed = games.split(",");
const acceptedIds = GAMES.map((game) => game.id);
const unmatched = parsed.filter((id) => !acceptedIds.includes(id));
if (unmatched.length > 0) throw new Error(`Invalid game ID: ${unmatched.join(", ")}`);
const matched = parsed.filter((id) => acceptedIds.includes(id.toLowerCase()));
return getGames(matched);
}
|