UNPKG

screenscraper-js

Version:
89 lines (88 loc) 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformGame = void 0; function omit(obj, keys) { const keysToRemove = new Set(keys.flat()); return Object.fromEntries( // convert the entries back to object Object.entries(obj) // convert the object to entries .filter(([k]) => !keysToRemove.has(k)) // remove entries with keys that exist in the Set ); } const filterMedia = (media) => media.filter((m) => { if (m.type === "pictoliste" || m.type === "pictomonochrome" || m.type === "pictocouleur" || m.type === "wheel-steel" || m.type === "wheel-carbon" || m.type === "themehs") { return false; } if (!m.region) { return true; } if (m.type === "manuel" && m.region === "asi") { return true; } if (m.type === "wheel-hd") { return true; } return (m.region === "wor" || m.region === "eu" || m.region === "ss" || m.region === "us" || m.region === "au"); }); const transformGame = (game, language) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const name = (_b = (_a = game.noms.filter((n) => n.region === "wor" || n.region === "us" || n.region === "eu" || n.region === "ss")) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text; return { id: game.id, publisher: game.editeur, developer: game.developpeur, players: (_c = game.joueurs) === null || _c === void 0 ? void 0 : _c.text, rotation: game.rotation, rating: (_d = game.note) === null || _d === void 0 ? void 0 : _d.text, system: game.systeme, name, synopsis: (_f = (_e = game.synopsis) === null || _e === void 0 ? void 0 : _e.find((s) => s.langue === language)) === null || _f === void 0 ? void 0 : _f.text, classifications: game.classifications, dates: game.dates, family: (_g = game === null || game === void 0 ? void 0 : game.familles) === null || _g === void 0 ? void 0 : _g.map((f) => { var _a, _b; return { id: f.id, shortName: f.nomcourt, name: (_b = (_a = f.noms) === null || _a === void 0 ? void 0 : _a.find((s) => s.langue === language)) === null || _b === void 0 ? void 0 : _b.text, }; }), genres: (_h = game === null || game === void 0 ? void 0 : game.genres) === null || _h === void 0 ? void 0 : _h.map((f) => { var _a; return { id: f.id, name: (_a = f.noms.find((s) => s.langue === language)) === null || _a === void 0 ? void 0 : _a.text, }; }), modes: (_j = game === null || game === void 0 ? void 0 : game.modes) === null || _j === void 0 ? void 0 : _j.map((f) => { var _a; return { id: f.id, name: (_a = f.noms.find((s) => s.langue === language)) === null || _a === void 0 ? void 0 : _a.text, }; }), media: (_k = filterMedia(game.medias)) === null || _k === void 0 ? void 0 : _k.reduce((acc, curr) => { const cleanCurr = omit(curr, ["sha1", "crc", "type", "parent", "md5"]); if (!acc[curr.type]) { acc[curr.type] = [cleanCurr]; } else { acc[curr.type] = [...acc[curr.type], cleanCurr]; } return acc; }, {}), }; }; exports.transformGame = transformGame;