country-data-filter 1.0.7 → 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.
Files changed (2) hide show
  1. package/package.json +6 -5
  2. package/src/index.js +11 -67
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "country-data-filter",
3
- "version": "1.0.7",
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/LK.js",
28
- "src/countries.js"
29
+ "src/countries/*.js"
29
30
  ]
30
31
  }
package/src/index.js CHANGED
@@ -1,60 +1,20 @@
1
- // src/index.js
1
+ import { countryData } from "./country-data.js";
2
2
 
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
- */
41
- function getProvincesByCountry(code) {
3
+ // Function to get the list of province names by country code
4
+ export function getProvincesByCountry(code) {
42
5
  const country = countryData[code];
43
6
  if (country) {
7
+ // Return an array of province names
44
8
  return Object.values(country.province).map((province) => province.name);
45
9
  }
46
10
  return [];
47
11
  }
48
12
 
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
- */
55
- function getDistrictsByProvince(countryCode, provinceName) {
13
+ // Function to get a list of district names by country code and province name
14
+ export function getDistrictsByProvince(countryCode, provinceName) {
56
15
  const country = countryData[countryCode];
57
16
  if (country && country.province[provinceName]) {
17
+ // Return an array of district names
58
18
  return Object.values(country.province[provinceName].districts).map(
59
19
  (district) => district.name
60
20
  );
@@ -62,14 +22,8 @@ function getDistrictsByProvince(countryCode, provinceName) {
62
22
  return [];
63
23
  }
64
24
 
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
- */
72
- function getCityByDistrict(countryCode, provinceName, districtName) {
25
+ // Function to get city details by country code, province name, and district name
26
+ export function getCityByDistrict(countryCode, provinceName, districtName) {
73
27
  const country = countryData[countryCode];
74
28
  const province = country.province[provinceName];
75
29
  if (province && province.districts[districtName]) {
@@ -78,21 +32,11 @@ function getCityByDistrict(countryCode, provinceName, districtName) {
78
32
  return null;
79
33
  }
80
34
 
81
- /**
82
- * List all available functions.
83
- * @returns {Object} - An object containing references to all the functions.
84
- */
85
- function listFunctions() {
35
+ // Function to list all available functions
36
+ export function listFunctions() {
86
37
  return {
87
38
  getProvincesByCountry,
88
39
  getDistrictsByProvince,
89
40
  getCityByDistrict,
90
41
  };
91
42
  }
92
-
93
- module.exports = {
94
- getProvincesByCountry,
95
- getDistrictsByProvince,
96
- getCityByDistrict,
97
- listFunctions,
98
- };