@andreasnicolaou/country-kit
Version:
A comprehensive package for working with country data. Includes ISO codes, names in multiple languages, capitals, currencies, continents and more.
48 lines (47 loc) • 1.63 kB
JavaScript
import countries from './countries';
export class CountryKit {
/**
* Get all countries.
* @returns countries
* @memberof CountryKit
*/
static getAllCountries() {
return countries;
}
/**
* Get countries within a specific continent.
* @param continent - The continent name
* @returns Array of countries in the continent
* @memberof CountryKit
*/
static getCountriesByContinent(continent) {
return Object.values(countries).filter((country) => country.continent?.toLowerCase() === continent.toLowerCase());
}
/**
* Get countries using a specific currency.
* @param currencyCode - ISO 4217 currency code
* @returns Array of countries using the currency
* @memberof CountryKit
*/
static getCountriesByCurrency(currencyCode) {
return Object.values(countries).filter((country) => country.currency.some((currency) => currency.code.toLowerCase() === currencyCode.toLowerCase()));
}
/**
* Get countries using a specific language.
* @param language
* @returns Array of countries using the language
* @memberof CountryKit
*/
static getCountriesByLanguage(language) {
return Object.values(countries).filter((country) => country.languages.some((lang) => lang.toLowerCase() === language.toLowerCase()));
}
/**
* Find a country by its ISO code.
* @param code - The country code (ISO 3166-1 alpha-2)
* @returns Country object or undefined
* @memberof CountryKit
*/
static getCountryByCode(code) {
return countries[code];
}
}