UNPKG

wiki-entity

Version:
26 lines (25 loc) 911 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEntityCountryCode = void 0; const countries = require("../../data/countries.json"); function getEntityCountryCode(wikiEntity) { if (!(wikiEntity === null || wikiEntity === void 0 ? void 0 : wikiEntity.claims)) { return null; } const countryIds = getEntityCountryIds(wikiEntity); const list = []; for (let id of countryIds) { if (countries[id]) { list.push(countries[id].cc2.toLowerCase()); } } return list.length ? list : null; } exports.getEntityCountryCode = getEntityCountryCode; function getEntityCountryIds(wikiEntity) { let prop = wikiEntity.claims.P17 || wikiEntity.claims.P27 || wikiEntity.claims.P495 || wikiEntity.claims.P1532; return (prop && prop.values.map((item) => item.value)) || []; }