nationstates.js
Version:
A wrapper to interact with the NationStates API.
131 lines • 5.54 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NationResult = void 0;
class NationResult {
constructor(result) {
this.freedom = {
civilrights: null,
economy: null,
politicalfreedom: null
};
this.govt = {
administration: null,
defence: null,
education: null,
environment: null,
healthcare: null,
commerce: null,
internationalAid: null,
lawAndOrder: null,
publicTransport: null,
socialEquality: null,
spirituality: null,
welfare: null
};
this.sectors = {
blackmarket: null,
government: null,
industry: null,
public: null
};
this.id = result['id'];
this.name = result['name'];
this.dbid = result['dbid'];
this.fullname = result['fullname'];
this.motto = result['motto'];
this.category = result['category'];
this.unstatus = result['unstatus'];
this.endorsements = result['endorsements'].split(',');
this.gavote = result['gavote'];
this.scvote = result['scvote'];
this.issuesAnswered = result['issues_answered'];
this.freedom.civilrights = result['freedom']['civilrights'];
this.freedom.economy = result['freedom']['economy'];
this.freedom.politicalfreedom = result['freedom']['politicalfreedom'];
this.region = result['region'];
this.population = result['population'];
this.tax = result['tax'];
this.animal = result['animal'];
this.animaltrait = result['animaltrait'];
this.currency = result['currency'];
this.flag = new URL(result['flag']);
this.banner = result['banner'];
this.banners = result['banners']['banner'];
this.demonym = result['demonym'];
this.demonym2plural = result['demonym2plural'];
this.gdp = result['gdp'];
this.income = result['income'];
this.richest = result['richest'];
this.poorest = result['poorest'];
this.majorindustry = result['majorindustry'];
this.crime = result['crime'];
this.govtPriority = result['govtpriority'];
this.govt.administration = result['govt']['administration'];
this.govt.defence = result['govt']['defence'];
this.govt.education = result['govt']['education'];
this.govt.environment = result['govt']['environment'];
this.govt.healthcare = result['govt']['healthcare'];
this.govt.commerce = result['govt']['commerce'];
this.govt.internationalAid = result['govt']['internationalaid'];
this.govt.lawAndOrder = result['govt']['lawandorder'];
this.govt.publicTransport = result['govt']['publictransport'];
this.govt.socialEquality = result['govt']['socialequality'];
this.govt.spirituality = result['govt']['spirituality'];
this.govt.welfare = result['govt']['welfare'];
this.sectors.blackmarket = result['sectors']['blackmarket'];
this.sectors.government = result['sectors']['government'];
this.sectors.industry = result['sectors']['industry'];
this.sectors.public = result['sectors']['public'];
this.govtdesc = result['govtdesc'];
this.industrydesc = result['industrydesc'];
this.notable = result['notable'];
this.notables = result['notables']['notable'];
this.admirable = result['admirable'];
this.admirables = result['admirables']['admirable'];
this.founded = result['founded'];
this.foundedTime = result['foundedtime'];
this.firstLogin = result['firstlogin'];
this.lastLogin = result['lastlogin'];
this.lastActivity = result['lastactivity'];
this.influence = result['influence'];
this.publicSector = result['publicsector'];
this.deaths = result['deaths'];
this.leader = result['leader'];
this.capital = result['capital'];
this.religion = result['religion'];
this.policies = result['policies'];
this.census = result['census'];
this.rcensus = result['rcensus'];
this.wcensus = result['wcensus'];
this.legislation = result['legislation'];
this.happenings = result['happenings'];
this.factbooks = result['factbooks'];
this.dispatches = result['dispatches'];
this.factbookList = result['factbooklist']['factbook'];
this.dispatchList = result['dispatchlist']['dispatch'];
this.waBadges = result['waBadges'];
this.tgcanrecruit = result['tgcanrecruit'];
this.tgcancampaign = result['tgcancampaign'];
this.happenings = result['happenings']['event'];
this.zombie = result['zombie'];
}
/**
* 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: NationResult._epochToDate(happening.timestamp),
text: happening.text.replaceAll('@@', '')
};
});
}
static _epochToDate(epoch) {
const date = new Date(0);
date.setUTCSeconds(epoch);
return date;
}
}
exports.NationResult = NationResult;
//# sourceMappingURL=nation_result.js.map