项目作者: annexare

项目描述 :
Countries, Languages & Continents data (capital and currency, native name, calling codes).
高级语言: JavaScript
项目地址: git://github.com/annexare/Countries.git
创建时间: 2014-07-06T16:44:51Z
项目社区:https://github.com/annexare/Countries

开源协议:MIT License

下载


Countries, Languages & Continents data

Monthly Downloads
NPM
Packagist
CI: JS
CI: PHP
Twitter

Continents & countries: ISO 3166-1 alpha-2 code (with alpha-2 to alpha-3 set), name, ISO 639-1 languages, capital and ISO 4217 currency codes, native name, calling codes.
Lists are available in JSON, CSV and SQL formats.
Also, contains separate JSON files with additional country Emoji flags data.

Version 3.0: Breaking changes

Version 3 comes with some data structure changes.
It was completely reworked under the hood with TypeScript, ESM exports and Turborepo file structure.

Everything is strongly typed so you can easily use data with auto-complete in your IDE.

Note: If your projects depend on the old structure, carefully specify required versions in your dependencies.

Installation

Package is available via:

  • NPM npm install countries-list
  • Composer / Packagist composer require annexare/countries-list

Usage (version 3.x)

Module exports continents, countries, languages and utility functions.

  1. // Interfaces and types
  2. import type {
  3. ICountry,
  4. ICountryData,
  5. ILanguage,
  6. TContinentCode,
  7. TCountryCode,
  8. TLanguageCode,
  9. } from 'countries-list'
  10. // Main data and utils
  11. import { continents, countries, languages } from 'countries-list'
  12. // Utils
  13. import { getCountryCode, getCountryData, getCountryDataList, getEmojiFlag } from 'countries-list'
  14. // Minimal data in JSON
  15. import countries2to3 from 'countries-list/minimal/countries.2to3.min.json'
  16. import countries3to2 from 'countries-list/minimal/countries.3to2.min.json'
  17. import languageNames from 'countries-list/minimal/languages.native.min'
  18. getCountryCode('Ukraine') // 'UA'
  19. getCountryCode('Україна') // 'UA'
  20. getCountryData('UA') // ICountryData

Built files are in the dist directory of this repository, and packages/countries directory contains source data.

Note: JS build contains ES modules, CommonJS and IIFE (for now)

  • CJS cjs/index.js
  • ESM mjs/index.js
  • IIFE index.iife.js

Data structure examples

  1. const continents = {
  2. AF: 'Africa',
  3. AN: 'Antarctica',
  4. AS: 'Asia',
  5. EU: 'Europe',
  6. NA: 'North America',
  7. OC: 'Oceania',
  8. SA: 'South America',
  9. }
  10. const countries = {
  11. // ...
  12. UA: {
  13. name: 'Ukraine',
  14. native: 'Україна',
  15. phone: [380],
  16. continent: 'EU',
  17. capital: 'Kyiv',
  18. currency: ['UAH'],
  19. languages: ['uk'],
  20. },
  21. // ...
  22. }
  23. const languages = {
  24. // ...
  25. uk: {
  26. name: 'Ukrainian',
  27. native: 'Українська',
  28. },
  29. ur: {
  30. name: 'Urdu',
  31. native: 'اردو',
  32. rtl: 1,
  33. },
  34. // ...
  35. }

Contributing to this repository

Everything is generated from strongly typed files in packages/countries/src, including SQL file.

Everything in dist is generated,
so please make data related changes ONLY to files from packages/countries, commit them.
Use npm run build (or turbo build, turbo test) command to build/test generated files.

Credits

Prepared by Annexare Studio from different public sources.
Feel free to use it as you need in your apps
or send updates into this public repository.
It’s under MIT license.