Skip to content

Countries, country code in alpha-2, alpha-3, number code, method to get conversion between country code.

License

Notifications You must be signed in to change notification settings

nirvana-flame/countries-code

Repository files navigation

countries-code

License Known Vulnerabilities npm

Data fetched from https://unstats.un.org/unsd/methodology/m49/ (UN) and from Wikipedia

List of countries: With country object containing Alpha-2 code (e.g.IE), Alpha-3 code (e.g. IRL), and Number codes.

Example

const countriesQuery = require("countries-code");

console.log(countriesQuery.allCountriesList());
/*
[....,
 {
    "country_name_en": "Ireland",
    "country_name_fr": "Irlande (l')",
    "alpha2": "IE",
    "alpha3": "IRL",
    "number": "372"
},...] 
*/
console.log(countriesQuery.getAllAlphaTwoCodes());
// ["AF",.....]
console.log(countriesQuery.getAllAlphaThreeCodes());
// ["AFG",.....]

// Use getCountry to get country name by alpha code-2 or 3
console.log(countriesQuery.getCountry("IE"));
// "Ireland"
console.log(countriesQuery.getCountry("IRL"));
// "Ireland"

// Use convertAlphaCode to convert alpha code-2 to 3 or vice versa
console.log(countriesQuery.convertAlphaCode("IE"));
// "IRL"
console.log(countriesQuery.convertAlphaCode("IRL"));
// "IE"
import { countriesQuery } from "countries-code";

console.log(countriesQuery.allCountriesList());
/*
[....,
 {
    "country_name_en": "Ireland",
    "country_name_fr": "Irlande (l')",
    "alpha2": "IE",
    "alpha3": "IRL",
    "number": "372"
},...] 
*/
console.log(countriesQuery.getAllAlphaTwoCodes());
// ["AF",.....]
console.log(countriesQuery.getAllAlphaThreeCodes());
// ["AFG",.....]

// Use getCountry to get country name by alpha code-2 or 3
console.log(countriesQuery.getCountry("IE"));
// "Ireland"
console.log(countriesQuery.getCountry("IRL"));
// "Ireland"

// Use convertAlphaCode to convert alpha code-2 to 3 or vice versa
console.log(countriesQuery.convertAlphaCode("IE"));
// "IRL"
console.log(countriesQuery.convertAlphaCode("IRL"));
// "IE"

License

MIT

📨 🍀

About

Countries, country code in alpha-2, alpha-3, number code, method to get conversion between country code.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •