Skip to content

Commit

Permalink
feat: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
dmythro committed Sep 12, 2023
1 parent 189f8ab commit f42f74c
Showing 1 changed file with 72 additions and 69 deletions.
141 changes: 72 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,91 +26,94 @@ Package is available via:

- **NPM** `npm install countries-list`
- **Composer / Packagist** `composer require annexare/countries-list`
- **Bower** `bower install countries`

## Usage

Module exports `continents`, `countries`, `languages` and functions:
## Usage (version 3.x)

Module exports `continents`, `countries`, `languages` and utility functions.

```ts
// Interfaces and types
import type {
ICountry,
ICountryData,
ILanguage,
TContinentCode,
TCountryCode,
TLanguageCode,
} from 'countries-list'

// Main data and utils
import { continents, countries, languages } from 'countries-list'
// Utils
import { getCountryCode, getCountryData, getCountryDataList, getEmojiFlag } from 'countries-list'

// Minimal data in JSON
import countries2to3 from 'countries-list/minimal/countries.2to3.min.json'
import countries3to2 from 'countries-list/minimal/countries.3to2.min.json'
import languageNames from 'countries-list/minimal/languages.native.min'

getCountryCode('Ukraine') // 'UA'
getCountryCode('Україна') // 'UA'
getCountryData('UA') // ICountryData
```

- `getEmojiFlag(countryCode)`, where `countryCode` is alpha-2 `String`
- `getUnicode(emoji)`, where `emoji` is alpha-2 emoji flag `String`
Built files are in the `dist` directory of this repository.
The `packages/countries` directory contains source data.

Built files are in the `./dist` directory.
The `./data` directory contains source data.
**Note**: JS builds:

The consistent data is available from `./dist/data.*` files (JSON, SQL).
- CJS `index.min.js`.
- ESM `index.min.mjs`.
- IIFE `index.iife.min.js`.

**Note**: ES6 builds:
- CJS `./dist/index.min.js`.
- ESM `./dist/index.min.mjs`.
- IIFE `./dist/index.iife.min.js`.
## Data structure examples

**Note**: Country item `languages` field is an `Array` in JSON files to easily count and match items with a Language item.
TODO: But `currency` and `phone` calling codes may be a comma-separated `String`.
```ts
const continents = {
AF: 'Africa',
AN: 'Antarctica',
AS: 'Asia',
EU: 'Europe',
NA: 'North America',
OC: 'Oceania',
SA: 'South America',
}

## Data example
const countries = {
// ...
UA: {
name: 'Ukraine',
native: 'Україна',
phone: [380],
continent: 'EU',
capital: 'Kyiv',
currency: ['UAH'],
languages: ['uk'],
},
// ...
}

```
{
"continents": {
"AF": "Africa",
"AN": "Antarctica",
"AS": "Asia",
"EU": "Europe",
"NA": "North America",
"OC": "Oceania",
"SA": "South America"
const languages = {
// ...
uk: {
name: 'Ukrainian',
native: 'Українська',
},
"countries": {
"AE": {
"name": "United Arab Emirates",
"native": "دولة الإمارات العربية المتحدة",
"phone": "971",
"continent": "AS",
"capital": "Abu Dhabi",
"currency": "AED",
"languages": [
"ar"
],
"emoji": "🇦🇪",
"emojiU": "U+1F1E6 U+1F1EA"
},
...
"UA": {
"name": "Ukraine",
"native": "Україна",
"phone": "380",
"continent": "EU",
"capital": "Kyiv",
"currency": "UAH",
"languages": [
"uk"
],
"emoji": "🇺🇦",
"emojiU": "U+1F1FA U+1F1E6"
}
ur: {
name: 'Urdu',
native: 'اردو',
rtl: 1,
},
"languages": {
"ar": {
"name": "Arabic",
"native": "العربية",
"rtl": 1
},
...
"uk": {
"name": "Ukrainian",
"native": "Українська"
}
}
// ...
}
```

## Contributing

Everything is generated from files in `./data/`, including SQL file.
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 `./data/`, commit them.
Everything in `dist` is generated,
so please make data related changes **ONLY** to files from `packages/countries`, commit them.
Use `npm run build` command to build/test generated files.

## Credits
Expand Down

0 comments on commit f42f74c

Please sign in to comment.