Skip to content

Instantly share code, notes, and snippets.

@thatanjan
Created September 19, 2023 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatanjan/c50e7ab526d6b9c1a6a59b16d20c0765 to your computer and use it in GitHub Desktop.
Save thatanjan/c50e7ab526d6b9c1a6a59b16d20c0765 to your computer and use it in GitHub Desktop.
country data
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