country-data-filter 1.0.4 → 1.0.6

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 CHANGED
@@ -1,22 +1,17 @@
1
1
  {
2
2
  "name": "country-data-filter",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A package to filter country data",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "index.js",
7
6
  "scripts": {
8
- "build": "tsc",
9
7
  "test": "jest"
10
8
  },
11
9
  "devDependencies": {
12
- "@types/jest": "^29.0.0",
13
- "@types/node": "^20.0.0",
14
- "jest": "^29.0.0",
15
- "typescript": "^5.5.4"
10
+ "jest": "^29.0.0"
16
11
  },
17
12
  "repository": {
18
13
  "type": "git",
19
- "url": "https://github.com/knnadeera/country-data-filter.git"
14
+ "url": "https://github.com/knnadeera/country-data.git"
20
15
  },
21
16
  "keywords": [
22
17
  "country",
@@ -28,9 +23,8 @@
28
23
  "author": "K N Nadeera",
29
24
  "license": "ISC",
30
25
  "files": [
31
- "dist"
32
- ],
33
- "engines": {
34
- "node": ">=12.0.0"
35
- }
26
+ "src/index.js",
27
+ "src/countries/LK.js",
28
+ "src/countries.js"
29
+ ]
36
30
  }
@@ -0,0 +1,18 @@
1
+ export const LK = {
2
+ name: "Sri Lanka",
3
+ province: {
4
+ southern: {
5
+ name: "Southern",
6
+ districts: {
7
+ matara: {
8
+ name: "Matara",
9
+ cities: [{ name: "Weligama", postalCode: 85700 }],
10
+ },
11
+ galle: {
12
+ name: "Galle",
13
+ cities: [{ name: "Galle", postalCode: 80000 }],
14
+ },
15
+ },
16
+ },
17
+ },
18
+ };
package/src/index.js ADDED
@@ -0,0 +1,50 @@
1
+ const { countryData } = require("./country-data");
2
+
3
+ // Function to get the list of province names by country code
4
+ function getProvincesByCountry(code) {
5
+ const country = countryData.countries[code];
6
+ if (country) {
7
+ // Return an array of province names
8
+ return Object.values(country.province).map((province) => province.name);
9
+ }
10
+ return [];
11
+ }
12
+
13
+ // Function to get a list of district names by country code and province name
14
+ function getDistrictsByProvince(countryCode, provinceName) {
15
+ const country = countryData.countries[countryCode];
16
+ if (country && country.province[provinceName]) {
17
+ // Return an array of district names
18
+ return Object.values(country.province[provinceName].districts).map(
19
+ (district) => district.name
20
+ );
21
+ }
22
+ return [];
23
+ }
24
+
25
+ // Function to get city details by country code, province name, and district name
26
+ function getCityByDistrict(countryCode, provinceName, districtName) {
27
+ const country = countryData.countries[countryCode];
28
+ const province = country.province[provinceName];
29
+ if (province && province.districts[districtName]) {
30
+ return province.districts[districtName];
31
+ }
32
+ return null;
33
+ }
34
+
35
+ // Function to list all available functions
36
+ function listFunctions() {
37
+ return {
38
+ getProvincesByCountry,
39
+ getDistrictsByProvince,
40
+ getCityByDistrict,
41
+ };
42
+ }
43
+
44
+ // Export all functions
45
+ module.exports = {
46
+ getProvincesByCountry,
47
+ getDistrictsByProvince,
48
+ getCityByDistrict,
49
+ listFunctions,
50
+ };
package/dist/index.d.ts DELETED
@@ -1,35 +0,0 @@
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 DELETED
@@ -1,46 +0,0 @@
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
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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,IAAY;IACzC,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,OAAO,EAAE,CAAC;QACZ,oCAAoC;QACpC,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CACxC,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CACjC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CA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