Created
September 19, 2023 11:13
-
-
Save thatanjan/c50e7ab526d6b9c1a6a59b16d20c0765 to your computer and use it in GitHub Desktop.
country data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const finalData = [ | |
] | |
;(async () => { | |
const res = await fetch('https://restcountries.com/v3.1/all?fields=name,cca2,independent,idd') | |
const data = await res.json() | |
data.forEach(item => { | |
const {name: {common}, cca2, independent, idd}= item | |
const {root, suffixes} = idd | |
const phonePrefix = root + suffixes | |
if(independent) finalData.push({label:common, value: cca2, phonePrefix}) | |
}); | |
console.log(finalData) | |
finalData.sort((a, b) => a.label.localeCompare(b.label) ) | |
fs.writeFileSync('./temp.js', JSON.stringify(finalData, null, 2)) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment