i18n-countries-continents 1.0.2 β 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +171 -112
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.0.3] - 2026-03-27
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Rewrote README with fixed emoji rendering (broken flag/map emojis on npm)
|
|
12
|
+
- Added badges (npm version, downloads, license, TypeScript)
|
|
13
|
+
- Added yarn and pnpm installation commands
|
|
14
|
+
- Added sub-path imports section showing all tree-shakeable entry points
|
|
15
|
+
- Added separate Node.js ESM and CommonJS usage examples
|
|
16
|
+
- Added `SUPPORTED_LANGUAGES` constant to API reference
|
|
17
|
+
- Improved TypeScript types section with inline comments
|
|
18
|
+
- Replaced plain lists with tables for Data Coverage (Countries, Languages)
|
|
19
|
+
- Fixed duplicate `---` dividers in document
|
|
20
|
+
- Fixed `Data Format` section that incorrectly referenced `src/data/` (internal source path)
|
|
21
|
+
- Improved React, Vue, and Angular examples with more realistic code
|
|
22
|
+
- Cleaned up API reference descriptions with parameter documentation
|
|
23
|
+
|
|
8
24
|
## [1.0.2] - 2025-03-10
|
|
9
25
|
|
|
10
26
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# i18n-countries-continents
|
|
2
2
|
|
|
3
|
-
Get country, continent, and city names in different languages. **250 countries**, **7 continents**, and **4,010 cities** with full translations in 5 languages
|
|
3
|
+
Get country, continent, and city names in different languages. **250 countries**, **7 continents**, and **4,010 cities** with full translations in **5 languages**. Works in React, Angular, Vue, Svelte, Node.js, and any JavaScript environment.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/i18n-countries-continents)
|
|
6
|
+
[](https://www.npmjs.com/package/i18n-countries-continents)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
@@ -8,18 +13,30 @@ Get country, continent, and city names in different languages. **250 countries**
|
|
|
8
13
|
npm install i18n-countries-continents
|
|
9
14
|
```
|
|
10
15
|
|
|
16
|
+
```sh
|
|
17
|
+
yarn add i18n-countries-continents
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm add i18n-countries-continents
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
11
26
|
## Features
|
|
12
27
|
|
|
13
|
-
- π **250 countries**
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- ποΈ **4,010 cities**
|
|
17
|
-
- π **5 languages**
|
|
18
|
-
- π¦ **Zero dependencies**
|
|
19
|
-
- π€ **ISO 3166-1 codes**
|
|
20
|
-
- πͺ **TypeScript**
|
|
21
|
-
- β‘ **Tree-shakeable**
|
|
22
|
-
- π― Works with
|
|
28
|
+
- π **250 countries** β Complete coverage of all world countries
|
|
29
|
+
- π³οΈ **Country flags** β Flag emoji for every country
|
|
30
|
+
- πΊοΈ **7 continents** β All continents included
|
|
31
|
+
- ποΈ **4,010 cities** β Major cities from around the world
|
|
32
|
+
- π **5 languages** β English, Spanish, French, Arabic, Dutch (100% coverage)
|
|
33
|
+
- π¦ **Zero dependencies** β Lightweight and fast
|
|
34
|
+
- π€ **ISO 3166-1 codes** β Standard alpha-2 country codes
|
|
35
|
+
- πͺ **TypeScript** β Full type definitions included
|
|
36
|
+
- β‘ **Tree-shakeable** β Import only what you need
|
|
37
|
+
- π― **Universal** β Works with ESM and CommonJS
|
|
38
|
+
|
|
39
|
+
---
|
|
23
40
|
|
|
24
41
|
## Usage
|
|
25
42
|
|
|
@@ -28,8 +45,10 @@ npm install i18n-countries-continents
|
|
|
28
45
|
```js
|
|
29
46
|
import { getCountryName } from 'i18n-countries-continents';
|
|
30
47
|
|
|
31
|
-
console.log(getCountryName('FR', 'fr')); // France
|
|
32
|
-
console.log(getCountryName('FR', 'es')); // Francia
|
|
48
|
+
console.log(getCountryName('FR', 'fr')); // "France"
|
|
49
|
+
console.log(getCountryName('FR', 'es')); // "Francia"
|
|
50
|
+
console.log(getCountryName('DE', 'ar')); // "Ψ£ΩΩ
Ψ§ΩΩΨ§"
|
|
51
|
+
console.log(getCountryName('JP', 'nl')); // "Japan"
|
|
33
52
|
```
|
|
34
53
|
|
|
35
54
|
### 2. Get a country flag
|
|
@@ -40,6 +59,7 @@ import { getCountryFlag } from 'i18n-countries-continents';
|
|
|
40
59
|
console.log(getCountryFlag('US')); // πΊπΈ
|
|
41
60
|
console.log(getCountryFlag('FR')); // π«π·
|
|
42
61
|
console.log(getCountryFlag('JP')); // π―π΅
|
|
62
|
+
console.log(getCountryFlag('MA')); // π²π¦
|
|
43
63
|
```
|
|
44
64
|
|
|
45
65
|
### 3. List all countries in a language
|
|
@@ -48,10 +68,10 @@ console.log(getCountryFlag('JP')); // π―π΅
|
|
|
48
68
|
import { getCountries } from 'i18n-countries-continents';
|
|
49
69
|
|
|
50
70
|
const countries = getCountries('en');
|
|
51
|
-
countries.forEach(c => console.log(c.flag, c.code, c.name));
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
71
|
+
countries.forEach(c => console.log(c.flag, c.code, c.name, c.continent));
|
|
72
|
+
// πΊπΈ US United States NA
|
|
73
|
+
// π«π· FR France EU
|
|
74
|
+
// ...
|
|
55
75
|
```
|
|
56
76
|
|
|
57
77
|
### 4. Get a continent code by country code
|
|
@@ -60,6 +80,8 @@ countries.forEach(c => console.log(c.flag, c.code, c.name));
|
|
|
60
80
|
import { getContinentByCountry } from 'i18n-countries-continents';
|
|
61
81
|
|
|
62
82
|
console.log(getContinentByCountry('US')); // "NA"
|
|
83
|
+
console.log(getContinentByCountry('JP')); // "AS"
|
|
84
|
+
console.log(getContinentByCountry('BR')); // "SA"
|
|
63
85
|
```
|
|
64
86
|
|
|
65
87
|
### 5. Get a continent name in a specific language
|
|
@@ -67,7 +89,9 @@ console.log(getContinentByCountry('US')); // "NA"
|
|
|
67
89
|
```js
|
|
68
90
|
import { getContinentName } from 'i18n-countries-continents';
|
|
69
91
|
|
|
70
|
-
console.log(getContinentName('EU', 'es')); // Europa
|
|
92
|
+
console.log(getContinentName('EU', 'es')); // "Europa"
|
|
93
|
+
console.log(getContinentName('NA', 'fr')); // "AmΓ©rique du Nord"
|
|
94
|
+
console.log(getContinentName('AS', 'ar')); // "Ψ’Ψ³ΩΨ§"
|
|
71
95
|
```
|
|
72
96
|
|
|
73
97
|
### 6. List all continents in a language
|
|
@@ -75,8 +99,12 @@ console.log(getContinentName('EU', 'es')); // Europa
|
|
|
75
99
|
```js
|
|
76
100
|
import { getContinents } from 'i18n-countries-continents';
|
|
77
101
|
|
|
78
|
-
const continents = getContinents('
|
|
102
|
+
const continents = getContinents('nl');
|
|
79
103
|
continents.forEach(c => console.log(c.code, c.name));
|
|
104
|
+
// AF Afrika
|
|
105
|
+
// AS AziΓ«
|
|
106
|
+
// EU Europa
|
|
107
|
+
// ...
|
|
80
108
|
```
|
|
81
109
|
|
|
82
110
|
### 7. Get a city name in a specific language
|
|
@@ -84,9 +112,9 @@ continents.forEach(c => console.log(c.code, c.name));
|
|
|
84
112
|
```js
|
|
85
113
|
import { getCityName } from 'i18n-countries-continents';
|
|
86
114
|
|
|
87
|
-
console.log(getCityName('Paris', '
|
|
88
|
-
console.log(getCityName('
|
|
89
|
-
console.log(getCityName('
|
|
115
|
+
console.log(getCityName('Paris', 'ar')); // "Ψ¨Ψ§Ψ±ΩΨ³"
|
|
116
|
+
console.log(getCityName('London', 'fr')); // "Londres"
|
|
117
|
+
console.log(getCityName('Tokyo', 'ar')); // "Ψ·ΩΩΩΩ"
|
|
90
118
|
```
|
|
91
119
|
|
|
92
120
|
### 8. List all cities in a language
|
|
@@ -96,6 +124,9 @@ import { getCities } from 'i18n-countries-continents';
|
|
|
96
124
|
|
|
97
125
|
const cities = getCities('es');
|
|
98
126
|
cities.forEach(c => console.log(c.name, 'β', c.translatedName));
|
|
127
|
+
// Paris β ParΓs
|
|
128
|
+
// London β Londres
|
|
129
|
+
// ...
|
|
99
130
|
```
|
|
100
131
|
|
|
101
132
|
### 9. Search for cities
|
|
@@ -103,11 +134,8 @@ cities.forEach(c => console.log(c.name, 'β', c.translatedName));
|
|
|
103
134
|
```js
|
|
104
135
|
import { searchCities } from 'i18n-countries-continents';
|
|
105
136
|
|
|
106
|
-
// Search for cities containing "york" in English
|
|
107
137
|
const results = searchCities('york', 'en', 5);
|
|
108
138
|
results.forEach(c => console.log(c.name, 'β', c.translatedName));
|
|
109
|
-
|
|
110
|
-
// Output:
|
|
111
139
|
// East York β East York
|
|
112
140
|
// New York β New York
|
|
113
141
|
// North York β North York
|
|
@@ -121,161 +149,192 @@ results.forEach(c => console.log(c.name, 'β', c.translatedName));
|
|
|
121
149
|
### React
|
|
122
150
|
|
|
123
151
|
```jsx
|
|
124
|
-
import { getCountries } from 'i18n-countries-continents';
|
|
152
|
+
import { getCountries, getCountryFlag } from 'i18n-countries-continents';
|
|
125
153
|
|
|
126
|
-
function
|
|
154
|
+
function CountrySelector() {
|
|
127
155
|
const countries = getCountries('fr');
|
|
128
156
|
return (
|
|
129
|
-
<
|
|
130
|
-
{countries.map(c =>
|
|
131
|
-
|
|
157
|
+
<select>
|
|
158
|
+
{countries.map(c => (
|
|
159
|
+
<option key={c.code} value={c.code}>
|
|
160
|
+
{c.flag} {c.name}
|
|
161
|
+
</option>
|
|
162
|
+
))}
|
|
163
|
+
</select>
|
|
132
164
|
);
|
|
133
165
|
}
|
|
134
166
|
```
|
|
135
167
|
|
|
136
|
-
###
|
|
168
|
+
### Vue
|
|
137
169
|
|
|
138
|
-
```
|
|
170
|
+
```vue
|
|
171
|
+
<script setup>
|
|
139
172
|
import { getCountries } from 'i18n-countries-continents';
|
|
173
|
+
const countries = getCountries('es');
|
|
174
|
+
</script>
|
|
175
|
+
|
|
176
|
+
<template>
|
|
177
|
+
<ul>
|
|
178
|
+
<li v-for="c in countries" :key="c.code">{{ c.flag }} {{ c.name }}</li>
|
|
179
|
+
</ul>
|
|
180
|
+
</template>
|
|
181
|
+
```
|
|
140
182
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
183
|
+
### Angular
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { Component } from '@angular/core';
|
|
187
|
+
import { getCountries, Country } from 'i18n-countries-continents';
|
|
188
|
+
|
|
189
|
+
@Component({ selector: 'app-root', template: `
|
|
190
|
+
<li *ngFor="let c of countries">{{ c.flag }} {{ c.name }}</li>
|
|
191
|
+
` })
|
|
192
|
+
export class AppComponent {
|
|
193
|
+
countries: Country[] = getCountries('en');
|
|
144
194
|
}
|
|
145
195
|
```
|
|
146
196
|
|
|
147
|
-
###
|
|
197
|
+
### Node.js (ESM)
|
|
148
198
|
|
|
149
|
-
```
|
|
150
|
-
import {
|
|
199
|
+
```js
|
|
200
|
+
import { getCountryName, getContinentByCountry, getContinentName } from 'i18n-countries-continents';
|
|
151
201
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
202
|
+
const code = 'US';
|
|
203
|
+
const continent = getContinentByCountry(code); // "NA"
|
|
204
|
+
const name = getContinentName(continent, 'es'); // "NorteamΓ©rica"
|
|
205
|
+
console.log(`${code} is in ${name}`);
|
|
159
206
|
```
|
|
160
207
|
|
|
161
|
-
### Node.js
|
|
208
|
+
### Node.js (CommonJS)
|
|
162
209
|
|
|
163
|
-
```
|
|
164
|
-
const {
|
|
210
|
+
```js
|
|
211
|
+
const { getCountryName, getCountryFlag, getContinentByCountry } = require('i18n-countries-continents');
|
|
165
212
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
console.log(
|
|
213
|
+
console.log(getCountryName('US', 'en')); // "United States"
|
|
214
|
+
console.log(getCountryFlag('FR')); // π«π·
|
|
215
|
+
console.log(getContinentByCountry('JP')); // "AS"
|
|
169
216
|
```
|
|
170
217
|
|
|
171
|
-
|
|
218
|
+
### Sub-path imports (tree-shaking)
|
|
219
|
+
|
|
220
|
+
Import individual functions for the smallest possible bundle:
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
import getCountryName from 'i18n-countries-continents/get-country-name';
|
|
224
|
+
import getCountryFlag from 'i18n-countries-continents/get-country-flag';
|
|
225
|
+
import getCountries from 'i18n-countries-continents/get-countries';
|
|
226
|
+
import getContinents from 'i18n-countries-continents/get-continents';
|
|
227
|
+
import getContinentByCountry from 'i18n-countries-continents/get-continent-by-country';
|
|
228
|
+
import getContinentName from 'i18n-countries-continents/get-continent-name';
|
|
229
|
+
import getCityName from 'i18n-countries-continents/get-city-name';
|
|
230
|
+
import getCities from 'i18n-countries-continents/get-cities';
|
|
231
|
+
import searchCities from 'i18n-countries-continents/search-cities';
|
|
232
|
+
```
|
|
172
233
|
|
|
173
234
|
---
|
|
174
235
|
|
|
175
236
|
## Data Coverage
|
|
176
237
|
|
|
177
238
|
### Countries: 250
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
239
|
+
| Continent | Count |
|
|
240
|
+
|-----------|-------|
|
|
241
|
+
| Africa | 58 countries |
|
|
242
|
+
| Antarctica | 5 territories |
|
|
243
|
+
| Asia | 53 countries |
|
|
244
|
+
| Europe | 53 countries |
|
|
245
|
+
| North America | 41 countries |
|
|
246
|
+
| Oceania | 26 countries |
|
|
247
|
+
| South America | 14 countries |
|
|
185
248
|
|
|
186
249
|
### Continents: 7
|
|
187
250
|
All continents fully covered with translations in all 5 languages.
|
|
188
251
|
|
|
189
252
|
### Cities: 4,010
|
|
190
|
-
Major cities from around the world
|
|
191
|
-
- Capital cities
|
|
192
|
-
- Major metropolitan areas
|
|
193
|
-
- Important economic centers
|
|
194
|
-
- Cultural landmarks
|
|
253
|
+
Major cities from around the world β capital cities, major metropolitan areas, important economic centers, and cultural landmarks.
|
|
195
254
|
|
|
196
255
|
### Languages: 5
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
256
|
+
| Code | Language | Coverage |
|
|
257
|
+
|------|----------|----------|
|
|
258
|
+
| `en` | English | 100% |
|
|
259
|
+
| `es` | Spanish | 100% |
|
|
260
|
+
| `fr` | French | 100% |
|
|
261
|
+
| `ar` | Arabic | 100% |
|
|
262
|
+
| `nl` | Dutch | 100% |
|
|
202
263
|
|
|
203
264
|
---
|
|
204
265
|
|
|
205
266
|
## API Reference
|
|
206
267
|
|
|
207
|
-
### Country
|
|
268
|
+
### Country Functions
|
|
208
269
|
|
|
209
|
-
#### `getCountryName(code
|
|
270
|
+
#### `getCountryName(code, language?): string | undefined`
|
|
210
271
|
Get the name of a country by its ISO 3166-1 alpha-2 code.
|
|
272
|
+
- `code` β country code, e.g. `'US'`, `'FR'` (case-insensitive)
|
|
273
|
+
- `language` β one of `'en' | 'es' | 'fr' | 'ar' | 'nl'` (default: `'en'`)
|
|
211
274
|
|
|
212
|
-
#### `getCountryFlag(code
|
|
275
|
+
#### `getCountryFlag(code): string | undefined`
|
|
213
276
|
Get the flag emoji for a country by its ISO 3166-1 alpha-2 code.
|
|
214
277
|
|
|
215
|
-
#### `getCountries(language
|
|
216
|
-
Get all countries with their names and
|
|
278
|
+
#### `getCountries(language?): Country[]`
|
|
279
|
+
Get all 250 countries with their names, flags, and continent codes in the specified language.
|
|
280
|
+
|
|
281
|
+
#### `getContinentByCountry(code): string | undefined`
|
|
282
|
+
Get the continent code for a country (e.g. `'EU'`, `'AS'`, `'NA'`).
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
### Continent Functions
|
|
217
287
|
|
|
218
|
-
#### `
|
|
219
|
-
Get the continent code
|
|
288
|
+
#### `getContinentName(code, language?): string | undefined`
|
|
289
|
+
Get the name of a continent by its code (`'AF' | 'AN' | 'AS' | 'EU' | 'NA' | 'OC' | 'SA'`).
|
|
220
290
|
|
|
221
|
-
|
|
291
|
+
#### `getContinents(language?): Continent[]`
|
|
292
|
+
Get all 7 continents with their names in the specified language.
|
|
222
293
|
|
|
223
|
-
|
|
224
|
-
Get the name of a continent by its code.
|
|
294
|
+
---
|
|
225
295
|
|
|
226
|
-
|
|
227
|
-
Get all continents with their names in the specified language.
|
|
296
|
+
### City Functions
|
|
228
297
|
|
|
229
|
-
|
|
298
|
+
#### `getCityName(cityName, language?): string | undefined`
|
|
299
|
+
Get the translated name of a city by its English name.
|
|
230
300
|
|
|
231
|
-
#### `
|
|
232
|
-
Get
|
|
301
|
+
#### `getCities(language?): City[]`
|
|
302
|
+
Get all 4,010 cities with their translated names in the specified language.
|
|
233
303
|
|
|
234
|
-
#### `
|
|
235
|
-
|
|
304
|
+
#### `searchCities(query, language?, limit?): City[]`
|
|
305
|
+
Search for cities by name (searches both English and translated names).
|
|
306
|
+
- `limit` β max results to return (default: `10`)
|
|
236
307
|
|
|
237
|
-
|
|
238
|
-
Search for cities by name. Returns up to `limit` results (default: 10).
|
|
308
|
+
---
|
|
239
309
|
|
|
240
|
-
### Types
|
|
310
|
+
### Constants & Types
|
|
241
311
|
|
|
242
312
|
```typescript
|
|
313
|
+
import { SUPPORTED_LANGUAGES } from 'i18n-countries-continents';
|
|
314
|
+
// ['en', 'es', 'fr', 'ar', 'nl']
|
|
315
|
+
|
|
243
316
|
type SupportedLanguage = 'en' | 'es' | 'fr' | 'ar' | 'nl';
|
|
244
317
|
|
|
245
318
|
interface Country {
|
|
246
|
-
code: string;
|
|
247
|
-
continent: string;
|
|
248
|
-
name: string;
|
|
249
|
-
flag: string;
|
|
319
|
+
code: string; // ISO 3166-1 alpha-2, e.g. "US"
|
|
320
|
+
continent: string; // e.g. "NA"
|
|
321
|
+
name: string; // translated name
|
|
322
|
+
flag: string; // emoji, e.g. "πΊπΈ"
|
|
250
323
|
}
|
|
251
324
|
|
|
252
325
|
interface Continent {
|
|
253
|
-
code: string;
|
|
254
|
-
name: string;
|
|
326
|
+
code: string; // e.g. "EU"
|
|
327
|
+
name: string; // translated name
|
|
255
328
|
}
|
|
256
329
|
|
|
257
330
|
interface City {
|
|
258
|
-
name: string;
|
|
259
|
-
translatedName: string;
|
|
331
|
+
name: string; // English name
|
|
332
|
+
translatedName: string; // translated name
|
|
260
333
|
}
|
|
261
334
|
```
|
|
262
335
|
|
|
263
336
|
---
|
|
264
337
|
|
|
265
|
-
## Data Format
|
|
266
|
-
|
|
267
|
-
Country, continent, and city data is stored in JSON format in `src/data/` directory. This makes it easy to:
|
|
268
|
-
- Add new data or translations
|
|
269
|
-
- Update existing data
|
|
270
|
-
- Contribute via pull requests
|
|
271
|
-
- Parse and validate programmatically
|
|
272
|
-
|
|
273
|
-
---
|
|
274
|
-
|
|
275
|
-
---
|
|
276
|
-
|
|
277
338
|
## License
|
|
278
339
|
|
|
279
|
-
MIT
|
|
280
|
-
|
|
281
|
-
---
|
|
340
|
+
MIT Β© [Aissam EL Houref](https://github.com/ElhourefAissam)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-countries-continents",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Get country, continent, and city names in different languages. 250 countries, 7 continents, and 4,010 cities with 5 languages. Works in React, Angular, Vue, Node.js, and any JavaScript environment.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|