country-codes-list 1.6.12 → 2.1.0

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/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # country-codes-list
2
2
 
3
- Module with list of codes per country, which includes:
3
+ Module with list of codes per country, including country codes, currency codes, and more.
4
4
 
5
- - Country code (ISO 3166-1 alpha-2): Obtained from [Wikipedia](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
5
+ > [!WARNING]
6
+ > Release v2.0.0 introduces breaking changes with full TypeScript support and automated testing/publishing.
7
+
8
+ ## Features
9
+
10
+ - 2 digit country code (ISO 3166-1 alpha-2): Obtained from [Wikipedia](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
11
+ - 3 digit country code (ISO 3166-1 alpha-3): Obtained from [Wikipedia](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3)
6
12
  - Country Name: Each name in english and in the local country language
7
13
  - Currency Code (ISO 4217): Obtained from [Wikipedia](https://en.wikipedia.org/wiki/ISO_4217)
8
14
  - Currency Name (ISO 4217): Obtained from [Wikipedia](https://en.wikipedia.org/wiki/ISO_4217)
@@ -13,6 +19,30 @@ Module with list of codes per country, which includes:
13
19
  - Country Calling Code: The phone calling code for the country. Obtained from [Wikipedia](https://en.wikipedia.org/wiki/List_of_country_calling_codes#Alphabetical_listing_by_country_or_region).
14
20
  - Region: The Regional Classifications are from the [International Telecommunications Union](http://www.itu.int/ITU-D/ict/definitions/regions/index.html). Seen [here](https://meta.wikimedia.org/wiki/List_of_countries_by_regional_classification)
15
21
 
22
+ ## Installation
23
+
24
+ Install the package via npm:
25
+
26
+ ```bash
27
+ npm install --save country-codes-list
28
+ ```
29
+
30
+ ## Build & Test
31
+
32
+ To compile the package, run:
33
+
34
+ ```bash
35
+ npm run build
36
+ ```
37
+
38
+ The compiled output will be in the `dist/` folder.
39
+
40
+ To run tests:
41
+
42
+ ```bash
43
+ npm test
44
+ ```
45
+
16
46
  # Installation
17
47
 
18
48
  ## Install the NPM module
@@ -21,27 +51,87 @@ Module with list of codes per country, which includes:
21
51
  npm install --save country-codes-list
22
52
  ```
23
53
 
54
+ ## Migration Guide (v1.x to v2.0)
55
+
56
+ ### Breaking Changes
57
+
58
+ 1. **TypeScript Types**: If you were using types:
59
+
60
+ ```typescript
61
+ // Old (v1.x)
62
+ import { CountryProperty } from "country-codes-list";
63
+ const prop: CountryProperty = CountryProperty.countryCode;
64
+
65
+ // New (v2.0)
66
+ import type { CountryProperty } from "country-codes-list";
67
+ const prop: CountryProperty = "countryCode";
68
+ ```
69
+
70
+ 2. **Module Imports**: Now supports both CommonJS and ES modules:
71
+
72
+ ```javascript
73
+ // CommonJS (still works)
74
+ const countryCodes = require("country-codes-list");
75
+
76
+ // ES Modules (new)
77
+ import * as countryCodes from "country-codes-list";
78
+ ```
79
+
80
+ 3. **Stricter Types**: Some functions now have stricter type checking:
81
+ ```typescript
82
+ // This now requires valid country property keys
83
+ countryCodes.filter("invalidKey", "value"); // TypeScript error
84
+ ```
85
+
24
86
  ## Usage
25
87
 
26
- ### customList method:
27
-
28
- Just import the module and call the customList method. The first parameter must be the key you want for your object, and the second parameter must be a string with placeholders written as you need. The placeholders are defined between brackets (`{placeholder}`).
29
-
30
- The possible values for the object key and the placeholders are:
31
-
32
- - countryNameEn
33
- - countryNameLocal
34
- - countryCode
35
- - currencyCode
36
- - currencyNameEn
37
- - tinType
38
- - tinName
39
- - officialLanguageCode
40
- - officialLanguageNameEn
41
- - officialLanguageNameLocal
42
- - countryCallingCode
43
- - region
44
- - globalSouth
88
+ This package can be used in both CommonJS (JavaScript) and TypeScript environments.
89
+
90
+ ### CommonJS
91
+
92
+ ```js
93
+ const countryCodes = require("country-codes-list");
94
+
95
+ const myCountryCodesObject = countryCodes.customList(
96
+ "countryCode",
97
+ "[{countryCode}] {countryNameEn}: +{countryCallingCode}"
98
+ );
99
+
100
+ console.log(myCountryCodesObject);
101
+ ```
102
+
103
+ ### TypeScript
104
+
105
+ ```ts
106
+ import * as countryCodes from "country-codes-list";
107
+
108
+ const myCountryCodesObject = countryCodes.customList(
109
+ "countryCode",
110
+ "[{countryCode}] {countryNameEn}: +{countryCallingCode}"
111
+ );
112
+ console.log(myCountryCodesObject);
113
+ ```
114
+
115
+ ### API Details – customList Method
116
+
117
+ - The first parameter is the key used for the returned object's property.
118
+ - The second parameter is a string with placeholders (in `{placeholder}` format) replaced by corresponding country properties.
119
+
120
+ The available placeholders are:
121
+
122
+ - `countryNameEn`
123
+ - `countryNameLocal`
124
+ - `countryCode`
125
+ - `currencyCode`
126
+ - `currencyNameEn`
127
+ - `tinType`
128
+ - `tinName`
129
+ - `officialLanguageCode`
130
+ - `officialLanguageNameEn`
131
+ - `officialLanguageNameLocal`
132
+ - `countryCallingCode`
133
+ - `region`
134
+ - `globalSouth`
45
135
 
46
136
  #### Example
47
137
 
@@ -0,0 +1,21 @@
1
+ type CountryData = {
2
+ countryNameEn: string;
3
+ countryNameLocal: string;
4
+ countryCode: string;
5
+ countryCodeAlpha3: string;
6
+ currencyCode: string;
7
+ currencyNameEn: string;
8
+ tinType: string;
9
+ tinName: string;
10
+ officialLanguageCode: string;
11
+ officialLanguageNameEn: string;
12
+ officialLanguageNameLocal: string;
13
+ countryCallingCode: string;
14
+ areaCodes?: any[];
15
+ region: string;
16
+ flag: string;
17
+ };
18
+ type CountryProperty = keyof CountryData;
19
+ declare const countriesData: CountryData[];
20
+ export type { CountryData, CountryProperty };
21
+ export default countriesData;