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.
Files changed (3) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +171 -112
  3. 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. Works in React, Angular, Vue, Node.js, and any JavaScript environment.
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
+ [![npm version](https://img.shields.io/npm/v/i18n-countries-continents.svg)](https://www.npmjs.com/package/i18n-countries-continents)
6
+ [![npm downloads](https://img.shields.io/npm/dm/i18n-countries-continents.svg)](https://www.npmjs.com/package/i18n-countries-continents)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](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** - Complete coverage of all world countries
14
- - οΏ½ **Country flags** - Flag emoji for every country
15
- - οΏ½πŸ—ΊοΈ **7 continents** - All continents included
16
- - πŸ™οΈ **4,010 cities** - Major cities from around the world
17
- - 🌐 **5 languages** - English, Spanish, French, Arabic, Dutch (100% coverage)
18
- - πŸ“¦ **Zero dependencies** - Lightweight and fast
19
- - πŸ”€ **ISO 3166-1 codes** - Standard country codes
20
- - πŸ’ͺ **TypeScript** - Full type definitions included
21
- - ⚑ **Tree-shakeable** - Import only what you need
22
- - 🎯 Works with React, Angular, Vue, Svelte, Node.js, and plain JavaScript
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
- // Output: πŸ‡ΊπŸ‡Έ US United States
53
- // πŸ‡«πŸ‡· FR France
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('fr');
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', 'fr')); // Paris
88
- console.log(getCityName('Paris', 'ar')); // باريس
89
- console.log(getCityName('London', 'fr')); // Londres
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 CountryList() {
154
+ function CountrySelector() {
127
155
  const countries = getCountries('fr');
128
156
  return (
129
- <ul>
130
- {countries.map(c => <li key={c.code}>{c.name}</li>)}
131
- </ul>
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
- ### Angular
168
+ ### Vue
137
169
 
138
- ```typescript
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
- @Component({ /* ... */ })
142
- export class MyComponent {
143
- countries = getCountries('es');
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
- ### Vue
197
+ ### Node.js (ESM)
148
198
 
149
- ```javascript
150
- import { getCountries } from 'i18n-countries-continents';
199
+ ```js
200
+ import { getCountryName, getContinentByCountry, getContinentName } from 'i18n-countries-continents';
151
201
 
152
- export default {
153
- data() {
154
- return {
155
- countries: getCountries('en')
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
- ```javascript
164
- const { getContinentByCountry, getContinentName } = require('i18n-countries-continents');
210
+ ```js
211
+ const { getCountryName, getCountryFlag, getContinentByCountry } = require('i18n-countries-continents');
165
212
 
166
- const continentCode = getContinentByCountry('US');
167
- const continentName = getContinentName(continentCode, 'es');
168
- console.log(continentName); // NorteamΓ©rica
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
- - **Africa**: 58 countries
179
- - **Antarctica**: 5 territories
180
- - **Asia**: 53 countries
181
- - **Europe**: 53 countries
182
- - **North America**: 41 countries
183
- - **Oceania**: 26 countries
184
- - **South America**: 14 countries
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 including:
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
- - English (en) - 100%
198
- - Spanish (es) - 100%
199
- - French (fr) - 100%
200
- - Arabic (ar) - 100%
201
- - Dutch (nl) - 100%
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 Services
268
+ ### Country Functions
208
269
 
209
- #### `getCountryName(code: string, language?: SupportedLanguage): string | undefined`
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: string): string | undefined`
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?: SupportedLanguage): Country[]`
216
- Get all countries with their names and flags in the specified language.
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
- #### `getContinentByCountry(code: string): string | undefined`
219
- Get the continent code for a country.
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
- ### Continent Services
291
+ #### `getContinents(language?): Continent[]`
292
+ Get all 7 continents with their names in the specified language.
222
293
 
223
- #### `getContinentName(code: string, language?: SupportedLanguage): string | undefined`
224
- Get the name of a continent by its code.
294
+ ---
225
295
 
226
- #### `getContinents(language?: SupportedLanguage): Continent[]`
227
- Get all continents with their names in the specified language.
296
+ ### City Functions
228
297
 
229
- ### City Services
298
+ #### `getCityName(cityName, language?): string | undefined`
299
+ Get the translated name of a city by its English name.
230
300
 
231
- #### `getCityName(cityName: string, language?: SupportedLanguage): string | undefined`
232
- Get the translated name of a city.
301
+ #### `getCities(language?): City[]`
302
+ Get all 4,010 cities with their translated names in the specified language.
233
303
 
234
- #### `getCities(language?: SupportedLanguage): City[]`
235
- Get all cities with their names in the specified language.
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
- #### `searchCities(query: string, language?: SupportedLanguage, limit?: number): City[]`
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.2",
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",