country-codes-list 1.6.11 → 2.0.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.
@@ -0,0 +1,27 @@
1
+ name: Publish to NPM
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build-and-publish:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - name: Setup Node.js
14
+ uses: actions/setup-node@v3
15
+ with:
16
+ node-version: "16"
17
+ registry-url: "https://registry.npmjs.org"
18
+ - name: Install dependencies
19
+ run: npm install
20
+ - name: Build project
21
+ run: npm run build
22
+ - name: Run tests
23
+ run: npm test
24
+ - name: Publish package
25
+ run: npm publish
26
+ env:
27
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # country-codes-list
2
- Module with list of codes per country, which includes:
2
+
3
+ Module with list of codes per country, including country codes, currency codes, and more.
4
+
5
+ > [!WARNING]
6
+ > Release v2.0.0 introduces breaking changes with full TypeScript support and automated testing/publishing.
7
+
8
+ ## Features
3
9
 
4
10
  - Country code (ISO 3166-1 alpha-2): Obtained from [Wikipedia](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
5
11
  - Country Name: Each name in english and in the local country language
@@ -9,46 +15,135 @@ Module with list of codes per country, which includes:
9
15
  - TIN Name: Obtained from [Wikipedia](https://en.wikipedia.org/wiki/VAT_identification_number)
10
16
  - Official language code (usually from ISO 639-1, or ISO 639-3 otherwise)): Obtained from [Open Street Map](https://wiki.openstreetmap.org/wiki/Nominatim/Country_Codes). Returns only the first official language code per country
11
17
  - Official language name: Each name in english and in the local country language
12
- - 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).
18
+ - 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).
13
19
  - 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)
14
20
 
21
+ ## Installation
22
+
23
+ Install the package via npm:
24
+
25
+ ```bash
26
+ npm install --save country-codes-list
27
+ ```
28
+
29
+ ## Build & Test
30
+
31
+ To compile the package, run:
32
+
33
+ ```bash
34
+ npm run build
35
+ ```
36
+
37
+ The compiled output will be in the `dist/` folder.
38
+
39
+ To run tests:
40
+
41
+ ```bash
42
+ npm test
43
+ ```
15
44
 
16
45
  # Installation
46
+
17
47
  ## Install the NPM module
48
+
18
49
  ```bash
19
50
  npm install --save country-codes-list
20
51
  ```
21
52
 
53
+ ## Migration Guide (v1.x to v2.0)
54
+
55
+ ### Breaking Changes
56
+
57
+ 1. **TypeScript Types**: If you were using types:
58
+
59
+ ```typescript
60
+ // Old (v1.x)
61
+ import { CountryProperty } from "country-codes-list";
62
+ const prop: CountryProperty = CountryProperty.countryCode;
63
+
64
+ // New (v2.0)
65
+ import type { CountryProperty } from "country-codes-list";
66
+ const prop: CountryProperty = "countryCode";
67
+ ```
68
+
69
+ 2. **Module Imports**: Now supports both CommonJS and ES modules:
70
+
71
+ ```javascript
72
+ // CommonJS (still works)
73
+ const countryCodes = require("country-codes-list");
74
+
75
+ // ES Modules (new)
76
+ import * as countryCodes from "country-codes-list";
77
+ ```
78
+
79
+ 3. **Stricter Types**: Some functions now have stricter type checking:
80
+ ```typescript
81
+ // This now requires valid country property keys
82
+ countryCodes.filter("invalidKey", "value"); // TypeScript error
83
+ ```
84
+
22
85
  ## Usage
23
86
 
24
- ### customList method:
25
-
26
- 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}`).
27
-
28
- The possible values for the object key and the placeholders are:
29
- - countryNameEn
30
- - countryNameLocal
31
- - countryCode
32
- - currencyCode
33
- - currencyNameEn
34
- - tinType
35
- - tinName
36
- - officialLanguageCode
37
- - officialLanguageNameEn
38
- - officialLanguageNameLocal
39
- - countryCallingCode
40
- - region
41
- - globalSouth
87
+ This package can be used in both CommonJS (JavaScript) and TypeScript environments.
88
+
89
+ ### CommonJS
90
+
91
+ ```js
92
+ const countryCodes = require("country-codes-list");
93
+
94
+ const myCountryCodesObject = countryCodes.customList(
95
+ "countryCode",
96
+ "[{countryCode}] {countryNameEn}: +{countryCallingCode}"
97
+ );
98
+
99
+ console.log(myCountryCodesObject);
100
+ ```
101
+
102
+ ### TypeScript
103
+
104
+ ```ts
105
+ import * as countryCodes from "country-codes-list";
106
+
107
+ const myCountryCodesObject = countryCodes.customList(
108
+ "countryCode",
109
+ "[{countryCode}] {countryNameEn}: +{countryCallingCode}"
110
+ );
111
+ console.log(myCountryCodesObject);
112
+ ```
113
+
114
+ ### API Details – customList Method
115
+
116
+ - The first parameter is the key used for the returned object's property.
117
+ - The second parameter is a string with placeholders (in `{placeholder}` format) replaced by corresponding country properties.
118
+
119
+ The available placeholders are:
120
+
121
+ - `countryNameEn`
122
+ - `countryNameLocal`
123
+ - `countryCode`
124
+ - `currencyCode`
125
+ - `currencyNameEn`
126
+ - `tinType`
127
+ - `tinName`
128
+ - `officialLanguageCode`
129
+ - `officialLanguageNameEn`
130
+ - `officialLanguageNameLocal`
131
+ - `countryCallingCode`
132
+ - `region`
133
+ - `globalSouth`
42
134
 
43
135
  #### Example
44
136
 
45
137
  ```js
46
- const countryCodes = require('country-codes-list')
138
+ const countryCodes = require("country-codes-list");
47
139
 
48
- const myCountryCodesObject = countryCodes.customList('countryCode', '[{countryCode}] {countryNameEn}: +{countryCallingCode}')
140
+ const myCountryCodesObject = countryCodes.customList(
141
+ "countryCode",
142
+ "[{countryCode}] {countryNameEn}: +{countryCallingCode}"
143
+ );
49
144
  ```
50
145
 
51
- This will return an object like this one:
146
+ This will return an object like this one:
52
147
 
53
148
  ```js
54
149
  {
@@ -69,4 +164,4 @@ This will return an object like this one:
69
164
  ...
70
165
  }
71
166
 
72
- ```
167
+ ```
@@ -0,0 +1,20 @@
1
+ type CountryData = {
2
+ countryNameEn: string;
3
+ countryNameLocal: string;
4
+ countryCode: string;
5
+ currencyCode: string;
6
+ currencyNameEn: string;
7
+ tinType: string;
8
+ tinName: string;
9
+ officialLanguageCode: string;
10
+ officialLanguageNameEn: string;
11
+ officialLanguageNameLocal: string;
12
+ countryCallingCode: string;
13
+ areaCodes?: any[];
14
+ region: string;
15
+ flag: string;
16
+ };
17
+ type CountryProperty = keyof CountryData;
18
+ declare const countriesData: CountryData[];
19
+ export type { CountryData, CountryProperty };
20
+ export default countriesData;