components/InteractiveGlobe/countryMeta.jsjavascript
// Generated from the world-countries package (a devDependency, not shipped)
// by scripts/generate-country-meta.mjs - trimmed to the 4 fields actually
// used here, instead of bundling that package's ~1.4MB of translations/
// currencies/capitals/etc. at runtime. Re-run the script to refresh.
import countryMetas from "./countryMeta.data.json";
import { COUNTRY_NAME_ALIASES } from "../../services/config/globeDefaults";
// Alaska has no ISO country code of its own (it's a US state, not a
// sovereign country), so it can't be targeted through countryDisplay's
// cca3-keyed `countries` list like every other entry - countryPolygons.js
// splits it out of the USA's MultiPolygon under this synthetic id instead,
// and countryDisplay's `regions` list (see GlobePage.jsx) targets it here.
export const ALASKA_REGION_ID = "region:alaska";
const byCcn3 = new Map(countryMetas.map((c) => [c.ccn3, c]));
const byCca3 = new Map(countryMetas.map((c) => [c.cca3, c]));
const byCommonNameLower = new Map(countryMetas.map((c) => [c.commonName.toLowerCase(), c]));
/**
* Country metadata for a given ISO numeric code, e.g. countryPolygons.js
* decorating each world-atlas feature.
*
* @param {string} ccn3 - ISO numeric country code, e.g. "276" for Germany.
* @returns {{ccn3: string, cca3: string, commonName: string, continent: string}|undefined}
*/
export function countryMetaByCcn3(ccn3) {
return byCcn3.get(ccn3);
}
/**
* Country metadata for a given ISO alpha-3 code, e.g. resolving
* countryDisplay's `countries` entries (see countryColors.js).
*
* @param {string} cca3 - ISO alpha-3 country code, e.g. "DEU" for Germany.
* @returns {{ccn3: string, cca3: string, commonName: string, continent: string}|undefined}
*/
export function countryMetaByCca3(cca3) {
return byCca3.get(cca3);
}
/**
* Country metadata by common name, case-insensitively and resolving
* `COUNTRY_NAME_ALIASES` first (e.g. content authored with a country's
* short/colloquial name instead of world-countries' `commonName`). Currently
* unused elsewhere in `src` - kept alongside the other by-* lookups.
*
* @param {string} rawName - Country name as authored in content.
* @returns {{ccn3: string, cca3: string, commonName: string, continent: string}|undefined}
*/
export function countryMetaByName(rawName) {
const key = rawName.trim().toLowerCase();
const canonical = COUNTRY_NAME_ALIASES[key] ?? rawName.trim();
return byCommonNameLower.get(canonical.toLowerCase());
}
/**
* All countries in a given continent/region - value-partnership-globe-
* countries.json's `continents` entries are resolved through this (see
* countryColors.js).
*
* @param {string} continent - world-countries' `region` field: "Africa",
* "Americas", "Antarctic", "Asia", "Europe", "Oceania".
* @returns {Array<{ccn3: string, cca3: string, commonName: string, continent: string}>}
*/
export function countriesByContinent(continent) {
return countryMetas.filter((c) => c.continent === continent);
}