nationstates.js
Version:
A wrapper to interact with the NationStates API.
89 lines • 3.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegionResult = void 0;
class RegionResult {
constructor(result) {
this.id = result['id'];
this.name = result['name'];
this.dbid = result['dbid'];
this.lastUpdate = result['lastupdate'];
this.factbook = decodeURIComponent(result['factbook']);
this.dispatches = result['dispatches'].split(',');
this.numnations = result['numnations'];
this.nations = result['nations'].split(':');
this.delegate = result['delegate'];
this.delegateAuth = result['delegateauth'];
this.officers = result['officers']['officer'];
this.delegateVotes = result['delegatevotes'];
this.gaVote = {
for: result['gavote']['for'],
against: result['gavote']['against']
};
this.scVote = {
for: result['scvote']['for'],
against: result['scvote']['against']
};
this.founder = result['founder'];
this.founderAuth = result['founderauth'];
this.founded = result['founded'];
this.foundedTime = result['foundedtime'];
this.power = result['power'];
this.flag = new URL(result['flag']);
this.embassies = {
built: [],
requests: []
};
this._setEmbassies(result['embassies']['embassy']);
this.embassyRMB = result['embassyrmb'];
this.waBadges = result['wabadges'];
this.tags = result['tags']['tag'];
this.messages = result['messages']['post'].map(message => {
return {
id: message['id'],
timestamp: message['timestamp'],
nation: message['nation'],
status: message['status'],
likes: message['likes'],
likers: message['likers'] ? message['likers'].split(':') : [],
message: message['message']
};
});
this.happenings = result['happenings']['event'];
this.history = result['history']['event'];
this.census = result['census'];
this.censusRanks = result['censusranks'];
this.zombie = result['zombie'];
}
_setEmbassies(embassies) {
embassies.forEach(embassy => {
if (typeof embassy === 'string') {
this.embassies.built.push(embassy);
}
else if (typeof embassy === 'object') {
this.embassies.requests.push({
value: embassy['value'],
type: embassy['type']
});
}
});
}
/**
* Maps and returns all happenings after converting timestamps to a properly set Date object in UTC
* and fixing the format of the text by removing all @ symbols.
*/
formattedHappenings() {
return this.happenings.map(happening => {
return {
timestamp: RegionResult._epochToDate(happening.timestamp),
text: happening.text.replaceAll('@@', '')
};
});
}
static _epochToDate(epoch) {
const date = new Date(0);
date.setUTCSeconds(epoch);
return date;
}
}
exports.RegionResult = RegionResult;
//# sourceMappingURL=region_result.js.map