Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isValidLocation(location, features) {
features = features || {};
if (Array.isArray(location)) { // a [lon,lat] coordinate pair?
return !!(
location.length === 2 && Number.isFinite(location[0]) && Number.isFinite(location[1]) &&
location[0] >= -180 && location[0] <= 180 && location[1] >= -90 && location[1] <= 90
);
} else if (/^\S+\.geojson$/i.test(location)) { // a .geojson filename?
let featureId = location.replace('.geojson', '');
return !!features[featureId];
} else { // a country-coder string?
let ccmatch = CountryCoder.feature(location);
return !!ccmatch;
}
}
export function country(coordinates) {
const feature = CountryCoder.feature([...coordinates].reverse());
// Return no badge if the note is not inside a known country
if (!feature) {
return;
}
const emoji = [];
for (const codePoint of feature.properties.emojiFlag) {
emoji.push(codePoint.codePointAt(0).toString(16));
}
const url = `https://twemoji.maxcdn.com/v/latest/svg/${emoji.join('-')}.svg`;
return `<span class="my-1">
<img src="${url}" class="icon">
</span>`;
}