Skip to content

Commit f42f74c

Browse files
committed
feat: update README
1 parent 189f8ab commit f42f74c

File tree

1 file changed

+72
-69
lines changed

1 file changed

+72
-69
lines changed

README.md

+72-69
Original file line numberDiff line numberDiff line change
@@ -26,91 +26,94 @@ Package is available via:
2626

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

31-
## Usage
32-
33-
Module exports `continents`, `countries`, `languages` and functions:
30+
## Usage (version 3.x)
31+
32+
Module exports `continents`, `countries`, `languages` and utility functions.
33+
34+
```ts
35+
// Interfaces and types
36+
import type {
37+
ICountry,
38+
ICountryData,
39+
ILanguage,
40+
TContinentCode,
41+
TCountryCode,
42+
TLanguageCode,
43+
} from 'countries-list'
44+
45+
// Main data and utils
46+
import { continents, countries, languages } from 'countries-list'
47+
// Utils
48+
import { getCountryCode, getCountryData, getCountryDataList, getEmojiFlag } from 'countries-list'
49+
50+
// Minimal data in JSON
51+
import countries2to3 from 'countries-list/minimal/countries.2to3.min.json'
52+
import countries3to2 from 'countries-list/minimal/countries.3to2.min.json'
53+
import languageNames from 'countries-list/minimal/languages.native.min'
54+
55+
getCountryCode('Ukraine') // 'UA'
56+
getCountryCode('Україна') // 'UA'
57+
getCountryData('UA') // ICountryData
58+
```
3459

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

38-
Built files are in the `./dist` directory.
39-
The `./data` directory contains source data.
63+
**Note**: JS builds:
4064

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

43-
**Note**: ES6 builds:
44-
- CJS `./dist/index.min.js`.
45-
- ESM `./dist/index.min.mjs`.
46-
- IIFE `./dist/index.iife.min.js`.
69+
## Data structure examples
4770

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

51-
## Data example
82+
const countries = {
83+
// ...
84+
UA: {
85+
name: 'Ukraine',
86+
native: 'Україна',
87+
phone: [380],
88+
continent: 'EU',
89+
capital: 'Kyiv',
90+
currency: ['UAH'],
91+
languages: ['uk'],
92+
},
93+
// ...
94+
}
5295

53-
```
54-
{
55-
"continents": {
56-
"AF": "Africa",
57-
"AN": "Antarctica",
58-
"AS": "Asia",
59-
"EU": "Europe",
60-
"NA": "North America",
61-
"OC": "Oceania",
62-
"SA": "South America"
96+
const languages = {
97+
// ...
98+
uk: {
99+
name: 'Ukrainian',
100+
native: 'Українська',
63101
},
64-
"countries": {
65-
"AE": {
66-
"name": "United Arab Emirates",
67-
"native": "دولة الإمارات العربية المتحدة",
68-
"phone": "971",
69-
"continent": "AS",
70-
"capital": "Abu Dhabi",
71-
"currency": "AED",
72-
"languages": [
73-
"ar"
74-
],
75-
"emoji": "🇦🇪",
76-
"emojiU": "U+1F1E6 U+1F1EA"
77-
},
78-
...
79-
"UA": {
80-
"name": "Ukraine",
81-
"native": "Україна",
82-
"phone": "380",
83-
"continent": "EU",
84-
"capital": "Kyiv",
85-
"currency": "UAH",
86-
"languages": [
87-
"uk"
88-
],
89-
"emoji": "🇺🇦",
90-
"emojiU": "U+1F1FA U+1F1E6"
91-
}
102+
ur: {
103+
name: 'Urdu',
104+
native: 'اردو',
105+
rtl: 1,
92106
},
93-
"languages": {
94-
"ar": {
95-
"name": "Arabic",
96-
"native": "العربية",
97-
"rtl": 1
98-
},
99-
...
100-
"uk": {
101-
"name": "Ukrainian",
102-
"native": "Українська"
103-
}
104-
}
107+
// ...
105108
}
106109
```
107110

108111
## Contributing
109112

110-
Everything is generated from files in `./data/`, including SQL file.
113+
Everything is generated from strongly typed files in `packages/countries/src`, including SQL file.
111114

112-
Everything in `./dist/` is generated,
113-
so please make data related changes **ONLY** to files from `./data/`, commit them.
115+
Everything in `dist` is generated,
116+
so please make data related changes **ONLY** to files from `packages/countries`, commit them.
114117
Use `npm run build` command to build/test generated files.
115118

116119
## Credits

0 commit comments

Comments
 (0)