From 52453e05077225f5ebef2ff01fda813adb2a614c Mon Sep 17 00:00:00 2001 From: Majid Taherkhani Date: Tue, 22 Dec 2020 15:41:30 +0330 Subject: [PATCH 1/3] get country by code_phone --- index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.js b/index.js index d831d02..1caf7e2 100644 --- a/index.js +++ b/index.js @@ -231,6 +231,17 @@ const getCountriesByConstitutionalForm = (constitutionalFormName) => { return result; } +/** + * Returns an array of objects, each containing `country`, `capital`, + * `currency` and `native_language` filtered by `country` . + * @param {string} phone_code The name (not case-sensitive) of the country + * @returns {Array} An array of country objects + */ +const getCountryDetailsByPhoneCode = (phone_code) => { + return getCountriesByObject(phone_code, "phone_code"); +}; + + /** * Returns an array of objects containing all countries, each containing `country`, `capital`, * `currency`, `native_language`, `famous_for`, `phone_code`, `flag` and `drive_direction` filtered by `is_landlocked` From cdc0fdd3f72569decdf370fa0c04404a0a703c37 Mon Sep 17 00:00:00 2001 From: Majid Taherkhani Date: Tue, 22 Dec 2020 16:10:58 +0330 Subject: [PATCH 2/3] api for get country details by language_codes #73 --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index 1caf7e2..ed6c7ec 100644 --- a/index.js +++ b/index.js @@ -55,6 +55,21 @@ const getCountryDetailsByCapital = (capital) => { return getCountriesByObject(capital, "capital"); }; +/** + * @param {string} language_code The name (not case-sensitive) of the language_codes of the country + * @returns {Array} An array of country objects + */ +const getCountryDetailsBylanguageCodes = (language_code) => { + let resultArray = []; + data.forEach((item) => { + if(item["language_codes"].includes(language_code)){ + resultArray.push(item); + } + }); + return resultArray; + +}; + /** * Returns an array of objects, each containing `country`, `capital`, * `currency` and `native_language` filtered by `country` . @@ -277,6 +292,7 @@ const getCountryNeighbors = (country) => { return data.filter(({ neighbors }) => neighbors.includes(foundCountry.iso.alpha_2)); }; + module.exports = { getRandomCountry, getNRandomCountriesData, From d2e989ddfdbfcbcfff3ce7a3f46df587ad180c7f Mon Sep 17 00:00:00 2001 From: Majid Taherkhani Date: Tue, 22 Dec 2020 17:05:53 +0330 Subject: [PATCH 3/3] api for get country details by range of size #74 --- index.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/index.js b/index.js index ed6c7ec..bf7fc89 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,36 @@ const getCountryDetailsBylanguageCodes = (language_code) => { }; +/** + * @param {integer} size The name (not case-sensitive) of the size of the country + * @returns {Array} An array of country objects + */ +const getCountryDetailsBySizeRangeKm = (size) => { + let resultArray = []; + data.forEach((item) => { + if(Math.abs(item.area.km2-size)<100){ + resultArray.push(item); + } + }); + return resultArray; + +}; + +/** + * @param {integer} size The name (not case-sensitive) of the size of the country + * @returns {Array} An array of country objects + */ +const getCountryDetailsBySizeRangeMi = (size) => { + let resultArray = []; + data.forEach((item) => { + if(Math.abs(item.area.mi2-size)<100){ + resultArray.push(item); + } + }); + return resultArray; + +}; + /** * Returns an array of objects, each containing `country`, `capital`, * `currency` and `native_language` filtered by `country` . @@ -310,4 +340,9 @@ module.exports = { getCountriesByConstitutionalForm, getCountriesByLandLock, getCountryNeighbors, + getCountryDetailsByPhoneCode, + getCountryDetailsBySizeRangeMi, + getCountryDetailsBySizeRangeKm, + getCountryDetailsBylanguageCodes, + };