country-data-filter 1.0.6 → 1.0.8
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/package.json +6 -5
- package/src/index.js +8 -16
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "country-data-filter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "A package to filter country data",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "jest"
|
|
8
9
|
},
|
|
9
10
|
"devDependencies": {
|
|
10
|
-
"jest": "^29.0.0"
|
|
11
|
+
"jest": "^29.0.0",
|
|
12
|
+
"typescript": "^5.0.0"
|
|
11
13
|
},
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
@@ -24,7 +26,6 @@
|
|
|
24
26
|
"license": "ISC",
|
|
25
27
|
"files": [
|
|
26
28
|
"src/index.js",
|
|
27
|
-
"src/countries
|
|
28
|
-
"src/countries.js"
|
|
29
|
+
"src/countries/*.js"
|
|
29
30
|
]
|
|
30
31
|
}
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { countryData } from "./country-data.js";
|
|
2
2
|
|
|
3
3
|
// Function to get the list of province names by country code
|
|
4
|
-
function getProvincesByCountry(code) {
|
|
5
|
-
const country = countryData
|
|
4
|
+
export function getProvincesByCountry(code) {
|
|
5
|
+
const country = countryData[code];
|
|
6
6
|
if (country) {
|
|
7
7
|
// Return an array of province names
|
|
8
8
|
return Object.values(country.province).map((province) => province.name);
|
|
@@ -11,8 +11,8 @@ function getProvincesByCountry(code) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// Function to get a list of district names by country code and province name
|
|
14
|
-
function getDistrictsByProvince(countryCode, provinceName) {
|
|
15
|
-
const country = countryData
|
|
14
|
+
export function getDistrictsByProvince(countryCode, provinceName) {
|
|
15
|
+
const country = countryData[countryCode];
|
|
16
16
|
if (country && country.province[provinceName]) {
|
|
17
17
|
// Return an array of district names
|
|
18
18
|
return Object.values(country.province[provinceName].districts).map(
|
|
@@ -23,8 +23,8 @@ function getDistrictsByProvince(countryCode, provinceName) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Function to get city details by country code, province name, and district name
|
|
26
|
-
function getCityByDistrict(countryCode, provinceName, districtName) {
|
|
27
|
-
const country = countryData
|
|
26
|
+
export function getCityByDistrict(countryCode, provinceName, districtName) {
|
|
27
|
+
const country = countryData[countryCode];
|
|
28
28
|
const province = country.province[provinceName];
|
|
29
29
|
if (province && province.districts[districtName]) {
|
|
30
30
|
return province.districts[districtName];
|
|
@@ -33,18 +33,10 @@ function getCityByDistrict(countryCode, provinceName, districtName) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Function to list all available functions
|
|
36
|
-
function listFunctions() {
|
|
36
|
+
export function listFunctions() {
|
|
37
37
|
return {
|
|
38
38
|
getProvincesByCountry,
|
|
39
39
|
getDistrictsByProvince,
|
|
40
40
|
getCityByDistrict,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
// Export all functions
|
|
45
|
-
module.exports = {
|
|
46
|
-
getProvincesByCountry,
|
|
47
|
-
getDistrictsByProvince,
|
|
48
|
-
getCityByDistrict,
|
|
49
|
-
listFunctions,
|
|
50
|
-
};
|