country-codes-list 1.6.12 → 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,6 +1,11 @@
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
+
5
+ > [!WARNING]
6
+ > Release v2.0.0 introduces breaking changes with full TypeScript support and automated testing/publishing.
7
+
8
+ ## Features
4
9
 
5
10
  - Country code (ISO 3166-1 alpha-2): Obtained from [Wikipedia](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
6
11
  - Country Name: Each name in english and in the local country language
@@ -13,6 +18,30 @@ Module with list of codes per country, which includes:
13
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).
14
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)
15
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
+ ```
44
+
16
45
  # Installation
17
46
 
18
47
  ## Install the NPM module
@@ -21,27 +50,87 @@ Module with list of codes per country, which includes:
21
50
  npm install --save country-codes-list
22
51
  ```
23
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
+
24
85
  ## Usage
25
86
 
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
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`
45
134
 
46
135
  #### Example
47
136
 
@@ -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;