country-data-filter 1.0.5 → 1.0.7

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,6 +1,6 @@
1
1
  {
2
2
  "name": "country-data-filter",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "A package to filter country data",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,7 +23,8 @@
23
23
  "author": "K N Nadeera",
24
24
  "license": "ISC",
25
25
  "files": [
26
- "./src/index.js",
27
- "./src/country-data.json"
26
+ "src/index.js",
27
+ "src/countries/LK.js",
28
+ "src/countries.js"
28
29
  ]
29
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 CHANGED
@@ -1,20 +1,60 @@
1
- const { countryData } = require("./country-data");
1
+ // src/index.js
2
2
 
3
- // Function to get the list of province names by country code
3
+ const { countryData } = require("./countries.js");
4
+
5
+ /**
6
+ * @typedef {Object} City
7
+ * @property {string} name
8
+ * @property {number} postalCode
9
+ */
10
+
11
+ /**
12
+ * @typedef {Object} District
13
+ * @property {string} name
14
+ * @property {City[]} cities
15
+ */
16
+
17
+ /**
18
+ * @typedef {Object} Province
19
+ * @property {string} name
20
+ * @property {Object<string, District>} districts
21
+ */
22
+
23
+ /**
24
+ * @typedef {Object} Country
25
+ * @property {string} name
26
+ * @property {Object<string, Province>} province
27
+ */
28
+
29
+ /**
30
+ * @type {Object<string, Country>}
31
+ */
32
+ const countryData = {
33
+ // Data here
34
+ };
35
+
36
+ /**
37
+ * Get the list of province names by country code.
38
+ * @param {string} code - The country code.
39
+ * @returns {string[]} - An array of province names.
40
+ */
4
41
  function getProvincesByCountry(code) {
5
- const country = countryData.countries[code];
42
+ const country = countryData[code];
6
43
  if (country) {
7
- // Return an array of province names
8
44
  return Object.values(country.province).map((province) => province.name);
9
45
  }
10
46
  return [];
11
47
  }
12
48
 
13
- // Function to get a list of district names by country code and province name
49
+ /**
50
+ * Get a list of district names by country code and province name.
51
+ * @param {string} countryCode - The country code.
52
+ * @param {string} provinceName - The province name.
53
+ * @returns {string[]} - An array of district names.
54
+ */
14
55
  function getDistrictsByProvince(countryCode, provinceName) {
15
- const country = countryData.countries[countryCode];
56
+ const country = countryData[countryCode];
16
57
  if (country && country.province[provinceName]) {
17
- // Return an array of district names
18
58
  return Object.values(country.province[provinceName].districts).map(
19
59
  (district) => district.name
20
60
  );
@@ -22,9 +62,15 @@ function getDistrictsByProvince(countryCode, provinceName) {
22
62
  return [];
23
63
  }
24
64
 
25
- // Function to get city details by country code, province name, and district name
65
+ /**
66
+ * Get city details by country code, province name, and district name.
67
+ * @param {string} countryCode - The country code.
68
+ * @param {string} provinceName - The province name.
69
+ * @param {string} districtName - The district name.
70
+ * @returns {District | null} - The district object or null if not found.
71
+ */
26
72
  function getCityByDistrict(countryCode, provinceName, districtName) {
27
- const country = countryData.countries[countryCode];
73
+ const country = countryData[countryCode];
28
74
  const province = country.province[provinceName];
29
75
  if (province && province.districts[districtName]) {
30
76
  return province.districts[districtName];
@@ -32,7 +78,10 @@ function getCityByDistrict(countryCode, provinceName, districtName) {
32
78
  return null;
33
79
  }
34
80
 
35
- // Function to list all available functions
81
+ /**
82
+ * List all available functions.
83
+ * @returns {Object} - An object containing references to all the functions.
84
+ */
36
85
  function listFunctions() {
37
86
  return {
38
87
  getProvincesByCountry,
@@ -41,7 +90,6 @@ function listFunctions() {
41
90
  };
42
91
  }
43
92
 
44
- // Export all functions
45
93
  module.exports = {
46
94
  getProvincesByCountry,
47
95
  getDistrictsByProvince,