项目作者: nirvana-flame

项目描述 :
Countries, country code in alpha-2, alpha-3, number code, method to get conversion between country code.
高级语言: JavaScript
项目地址: git://github.com/nirvana-flame/countries-code.git
创建时间: 2019-05-18T09:45:31Z
项目社区:https://github.com/nirvana-flame/countries-code

开源协议:MIT License

下载


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

  1. const countriesQuery = require("countries-code");
  2. console.log(countriesQuery.allCountriesList());
  3. /*
  4. [....,
  5. {
  6. "country_name_en": "Ireland",
  7. "country_name_fr": "Irlande (l')",
  8. "alpha2": "IE",
  9. "alpha3": "IRL",
  10. "number": "372"
  11. },...]
  12. */
  13. console.log(countriesQuery.getAllAlphaTwoCodes());
  14. // ["AF",.....]
  15. console.log(countriesQuery.getAllAlphaThreeCodes());
  16. // ["AFG",.....]
  17. // Use getCountry to get country name by alpha code-2 or 3
  18. console.log(countriesQuery.getCountry("IE"));
  19. // "Ireland"
  20. console.log(countriesQuery.getCountry("IRL"));
  21. // "Ireland"
  22. // Use convertAlphaCode to convert alpha code-2 to 3 or vice versa
  23. console.log(countriesQuery.convertAlphaCode("IE"));
  24. // "IRL"
  25. console.log(countriesQuery.convertAlphaCode("IRL"));
  26. // "IE"
  1. import { countriesQuery } from "countries-code";
  2. console.log(countriesQuery.allCountriesList());
  3. /*
  4. [....,
  5. {
  6. "country_name_en": "Ireland",
  7. "country_name_fr": "Irlande (l')",
  8. "alpha2": "IE",
  9. "alpha3": "IRL",
  10. "number": "372"
  11. },...]
  12. */
  13. console.log(countriesQuery.getAllAlphaTwoCodes());
  14. // ["AF",.....]
  15. console.log(countriesQuery.getAllAlphaThreeCodes());
  16. // ["AFG",.....]
  17. // Use getCountry to get country name by alpha code-2 or 3
  18. console.log(countriesQuery.getCountry("IE"));
  19. // "Ireland"
  20. console.log(countriesQuery.getCountry("IRL"));
  21. // "Ireland"
  22. // Use convertAlphaCode to convert alpha code-2 to 3 or vice versa
  23. console.log(countriesQuery.convertAlphaCode("IE"));
  24. // "IRL"
  25. console.log(countriesQuery.convertAlphaCode("IRL"));
  26. // "IE"

License

MIT

:incoming_envelope: :four_leaf_clover: