UNPKG

iso-by-coords

Version:
28 lines (27 loc) 1.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const geojson_geometries_lookup_1 = __importDefault(require("geojson-geometries-lookup")); const typings_1 = require("./typings"); const configureCountryIso = (options) => { const { map } = options; const worldLookup = new geojson_geometries_lookup_1.default(map); const countryFeatureToIsoMapper = (feature) => options.iso === typings_1.CountryISO.ALPHA_2 ? feature.properties.A2 : feature.properties.A3; return { getIsoCodes: (lat, lng) => { const countries = worldLookup.getContainers({ type: 'Point', coordinates: [lng, lat] }); if (countries.features.length > 0) { return [...new Set(countries.features.map(countryFeatureToIsoMapper))]; } return []; } }; }; exports.default = configureCountryIso;