country-data-filter 1.0.3 → 1.0.4
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/dist/index.d.ts +35 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/package.json +14 -7
- package/country-data.json +0 -18
- package/index.js +0 -31
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare const data: any;
|
|
2
|
+
interface City {
|
|
3
|
+
name: string;
|
|
4
|
+
postalCode: number;
|
|
5
|
+
}
|
|
6
|
+
interface District {
|
|
7
|
+
name: string;
|
|
8
|
+
cities: City[];
|
|
9
|
+
}
|
|
10
|
+
interface Province {
|
|
11
|
+
name: string;
|
|
12
|
+
districts: {
|
|
13
|
+
[key: string]: District;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface Country {
|
|
17
|
+
name: string;
|
|
18
|
+
province: {
|
|
19
|
+
[key: string]: Province;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface Data {
|
|
23
|
+
countries: {
|
|
24
|
+
[key: string]: Country;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
declare const jsonData: Data;
|
|
28
|
+
declare function getProvincesByCountry(code: string): string[];
|
|
29
|
+
declare function getDistrictsByProvince(countryCode: string, provinceName: string): string[];
|
|
30
|
+
declare function getCityByDistrict(countryCode: string, provinceName: string, districtName: string): District | null;
|
|
31
|
+
declare function listFunctions(): {
|
|
32
|
+
getProvincesByCountry: typeof getProvincesByCountry;
|
|
33
|
+
getDistrictsByProvince: typeof getDistrictsByProvince;
|
|
34
|
+
getCityByDistrict: typeof getCityByDistrict;
|
|
35
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const data = require("./country-data.json");
|
|
3
|
+
const jsonData = data;
|
|
4
|
+
// Function to get the list of province names by country code
|
|
5
|
+
function getProvincesByCountry(code) {
|
|
6
|
+
const country = jsonData.countries[code];
|
|
7
|
+
if (country) {
|
|
8
|
+
// Return an array of province names
|
|
9
|
+
return Object.values(country.province).map((province) => province.name);
|
|
10
|
+
}
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
// Function to get a list of district names by country code and province name
|
|
14
|
+
function getDistrictsByProvince(countryCode, provinceName) {
|
|
15
|
+
const country = jsonData.countries[countryCode];
|
|
16
|
+
if (country && country.province[provinceName]) {
|
|
17
|
+
// Return an array of district names
|
|
18
|
+
return Object.values(country.province[provinceName].districts).map((district) => district.name);
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
// Function to get city details by country code, province name, and district name
|
|
23
|
+
function getCityByDistrict(countryCode, provinceName, districtName) {
|
|
24
|
+
const country = jsonData.countries[countryCode];
|
|
25
|
+
const province = country.province[provinceName];
|
|
26
|
+
if (province && province.districts[districtName]) {
|
|
27
|
+
return province.districts[districtName];
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
// Function to list all available functions
|
|
32
|
+
function listFunctions() {
|
|
33
|
+
return {
|
|
34
|
+
getProvincesByCountry,
|
|
35
|
+
getDistrictsByProvince,
|
|
36
|
+
getCityByDistrict,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Export all functions
|
|
40
|
+
module.exports = {
|
|
41
|
+
getProvincesByCountry,
|
|
42
|
+
getDistrictsByProvince,
|
|
43
|
+
getCityByDistrict,
|
|
44
|
+
listFunctions,
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAiC5C,MAAM,QAAQ,GAAS,IAAY,CAAC;AAEpC,6DAA6D;AAC7D,SAAS,qBAAqB,CAAC,IA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,CAAC;AAED,uBAAuB;AACvB,MAAM,CAAC,OAAO,GAAG;IACf,qBAAqB;IACrB,sBAAsB;IACtB,iBAAiB;IACjB,aAAa;CACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "country-data-filter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A package to filter country data",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
7
9
|
"test": "jest"
|
|
8
10
|
},
|
|
9
11
|
"devDependencies": {
|
|
10
|
-
"jest": "^29.0.0"
|
|
12
|
+
"@types/jest": "^29.0.0",
|
|
13
|
+
"@types/node": "^20.0.0",
|
|
14
|
+
"jest": "^29.0.0",
|
|
15
|
+
"typescript": "^5.5.4"
|
|
11
16
|
},
|
|
12
17
|
"repository": {
|
|
13
18
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/knnadeera/country-data.git"
|
|
19
|
+
"url": "https://github.com/knnadeera/country-data-filter.git"
|
|
15
20
|
},
|
|
16
21
|
"keywords": [
|
|
17
22
|
"country",
|
|
@@ -23,7 +28,9 @@
|
|
|
23
28
|
"author": "K N Nadeera",
|
|
24
29
|
"license": "ISC",
|
|
25
30
|
"files": [
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=12.0.0"
|
|
35
|
+
}
|
|
29
36
|
}
|
package/country-data.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"countries": {
|
|
3
|
-
"LK": {
|
|
4
|
-
"name": "Sri Lanka",
|
|
5
|
-
"province": {
|
|
6
|
-
"southern": {
|
|
7
|
-
"name": "Southern",
|
|
8
|
-
"districts": {
|
|
9
|
-
"matara": {
|
|
10
|
-
"name": "Matara",
|
|
11
|
-
"cities": [{ "name": "Weligama", "postalCode": 85700 }]
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
package/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const data = require("./country-data.json");
|
|
2
|
-
|
|
3
|
-
// Function to get country by code
|
|
4
|
-
function getProvinceByCountry(code) {
|
|
5
|
-
return data.countries[code];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// Function to get province by country code and province name
|
|
9
|
-
// function getProvinceByCountryAndName(countryCode, provinceName) {
|
|
10
|
-
function getDistrictByProvince(countryCode, provinceName) {
|
|
11
|
-
const country = getProvinceByCountry(countryCode);
|
|
12
|
-
if (country) {
|
|
13
|
-
return country.province[provinceName];
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Function to get districts by country code, province name, and district name
|
|
19
|
-
function getCityByDistrict(countryCode, provinceName, districtName) {
|
|
20
|
-
const province = getDistrictByProvince(countryCode, provinceName);
|
|
21
|
-
if (province) {
|
|
22
|
-
return province.districts[districtName];
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = {
|
|
28
|
-
getProvinceByCountry,
|
|
29
|
-
getDistrictByProvince,
|
|
30
|
-
getCityByDistrict,
|
|
31
|
-
};
|