kartrider.js
Version:
KartRider Nexon API Node.js library
29 lines (28 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatchList = void 0;
const MatchInfo_1 = require("./MatchInfo");
class MatchList {
constructor(client, userInfo, data, page) {
this.user = userInfo;
if (!this.user.name)
this.user.name = data.nickName;
this.matchList = resolveMatchList(client, data.matches);
this.limit = page === null || page === void 0 ? void 0 : page.limit;
this.offset = page === null || page === void 0 ? void 0 : page.offset;
}
}
exports.MatchList = MatchList;
function _MargeTypefromMatchObject(data) {
let result = [];
data.forEach(e => result = result.concat(e.matches));
return result;
}
function _SortDatefromMatchList(data) {
return data.sort((a, b) => Date.parse(b.endTime) - Date.parse(a.endTime));
}
function resolveMatchList(client, raw) {
const marge = _MargeTypefromMatchObject(raw);
const sort = _SortDatefromMatchList(marge);
return sort.map(MatchData => new MatchInfo_1.MatchInfo(client, MatchData));
}