what-to-play
Version:
Score aggregator for lists of games
29 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getData = void 0;
const howlongtobeat_1 = require("howlongtobeat");
const search_1 = require("./search");
const hltbService = new howlongtobeat_1.HowLongToBeatService();
async function getData(game) {
const results = await hltbService.search(game);
const bestResult = (0, search_1.closestSearchResult)(game, results, searchResult => searchResult.name);
if (bestResult == undefined) {
return undefined;
}
return {
name: bestResult === null || bestResult === void 0 ? void 0 : bestResult.name,
times: {
mainStory: nonZero(bestResult === null || bestResult === void 0 ? void 0 : bestResult.gameplayMain),
mainPlusExtra: nonZero(bestResult === null || bestResult === void 0 ? void 0 : bestResult.gameplayMainExtra),
completionist: nonZero(bestResult === null || bestResult === void 0 ? void 0 : bestResult.gameplayCompletionist),
},
url: `https://howlongtobeat.com/game/${bestResult.id}`
};
}
exports.getData = getData;
function nonZero(num) {
if (num === 0)
return undefined;
return num;
}
//# sourceMappingURL=howlongtobeat.js.map