country-data-filter 1.0.0

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.
@@ -0,0 +1,18 @@
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 ADDED
@@ -0,0 +1,31 @@
1
+ const data = require("./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
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "country-data-filter",
3
+ "version": "1.0.0",
4
+ "description": "A package to filter country data",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/knnadeera/country-data.git"
12
+ },
13
+ "keywords": [
14
+ "country",
15
+ "data",
16
+ "province",
17
+ "filter",
18
+ "city"
19
+ ],
20
+ "author": "K N Nadeera",
21
+ "license": "ISC"
22
+ }