DEV Community

Akash Yadav
Akash Yadav

Posted on

Atlas

import CountryFlagMappings from "./atlas-countryflags";
import CountryCitiesData from "./atlas-countrycity";
import CountryDialCodesMapping from "./atlas-countrydialcodes";
import CurrenciesData from "./atlas-currencies";

function CountryFlagEmoji(country) {
    try {
        const shortCode = CountryFlagMappings[country.trim()]; 
        return String.fromCodePoint(...[...shortCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt(0)));
    }
    catch (error) {
        return '🌐';
    }
}

function GetCountries() {
    return Object.keys(CountryCitiesData);
}

function GetCountriesWithFlags() {
    const countries = Object.keys(CountryCitiesData);

    const countriesWithFlags = countries.map(country => {
        return {
            label: `${CountryFlagEmoji(country)} ${country}`,
            value: country
        }
    });

    return countriesWithFlags;
}

function GetCitiesByCountry(country) {
    return CountryCitiesData[country];
}

function GetCountryDialCodes() {
    return CountryDialCodesMapping;
}

function GetDialCodesByCountry(country) {
    return CountryDialCodesMapping[country];
}

function GetCountryByDialCode(dialCode) {
    const countries = GetCountries();
    const country = countries.find(country => CountryDialCodesMapping[country] === dialCode);
    return country;
}

function GetCurrencies() {
    return Object.keys(CurrenciesData);
}

function GetCurrenciesArray() {
    const currencies = GetCurrencies();

    const currenciesArray = Object.keys(currencies).map(currency => {
        return {
            label: `${currency} (${currencies[currency]})`,
            value: currencies[currency]
        }
    });

    return currenciesArray;
}

function GetCurrencyCodeByName(name) {
    return CurrenciesData[name];
}

function GetCurrencyNameByCode(code) {
    const currencies = GetCurrencies();
    const currency = currencies.find(currency => CurrenciesData[currency] === code);
    return currency;
}

export { CountryFlagEmoji, GetCountries, GetCountriesWithFlags, GetCitiesByCountry, GetCountryDialCodes, GetDialCodesByCountry, GetCountryByDialCode, GetCurrencies, GetCurrenciesArray, GetCurrencyCodeByName, GetCurrencyNameByCode };
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay