@maxmind/geoip2-node
Version:
Node.js API for GeoIP2 webservice client and database reader
46 lines (45 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
class Country {
constructor(response, ipAddress, network) {
var _a, _b;
var _c, _d;
const camelcaseResponse = (0, utils_1.camelcaseKeys)(response);
this.continent = camelcaseResponse.continent || undefined;
this.country = camelcaseResponse.country || undefined;
this.maxmind = camelcaseResponse.maxmind || undefined;
this.registeredCountry =
this.setBooleanRegisteredCountry(camelcaseResponse.registeredCountry) ||
undefined;
this.representedCountry = camelcaseResponse.representedCountry || undefined;
this.traits = this.setBooleanTraits(camelcaseResponse.traits || {});
(_a = (_c = this.traits).ipAddress) !== null && _a !== void 0 ? _a : (_c.ipAddress = ipAddress);
(_b = (_d = this.traits).network) !== null && _b !== void 0 ? _b : (_d.network = network);
}
setBooleanTraits(traits) {
const booleanTraits = [
'isAnonymous',
'isAnonymousProxy',
'isAnonymousVpn',
'isAnycast',
'isHostingProvider',
'isLegitimateProxy',
'isPublicProxy',
'isResidentialProxy',
'isSatelliteProvider',
'isTorExitNode',
];
booleanTraits.forEach((trait) => {
traits[trait] = !!traits[trait];
});
return traits;
}
setBooleanRegisteredCountry(country) {
if (country) {
country.isInEuropeanUnion = !!country.isInEuropeanUnion;
}
return country;
}
}
exports.default = Country;