countries-geo 0.0.5 → 0.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.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cities_by_continent = exports.cities_by_country = exports.cities_by_state = exports.cities = void 0;
7
7
  const en_json_1 = __importDefault(require("../data/en.json"));
8
8
  // Cities
9
- const cities = () => en_json_1.default.flatMap((continent) => continent.cn).flatMap(country => country.s || []).flatMap(state => state.c || []).map(city => ({ iso: city.i, name: city.n }));
9
+ const cities = () => en_json_1.default.flatMap((continent) => continent.cn).flatMap((country) => country.s || []).flatMap((state) => state.c || []).filter((city) => city.i).map((city) => ({ iso: city.i, name: city.n }));
10
10
  exports.cities = cities;
11
11
  const cities_by_state = (iso) => {
12
12
  try {
@@ -49,8 +49,9 @@ exports.cities_by_state = cities_by_state;
49
49
  const cities_by_country = (iso) => {
50
50
  return en_json_1.default
51
51
  .flatMap((continent) => continent.cn)
52
- .find(country => country.i === iso)
52
+ .find((country) => country.i === iso)
53
53
  ?.s?.flatMap((state) => state.c || [])
54
+ ?.filter((city) => city.i)
54
55
  ?.map((city) => ({ iso: city.i, name: city.n })) || [];
55
56
  };
56
57
  exports.cities_by_country = cities_by_country;
@@ -61,6 +62,7 @@ const cities_by_continent = (iso) => {
61
62
  return continent.cn
62
63
  .flatMap((country) => country.s || [])
63
64
  .flatMap((state) => state.c || [])
65
+ .filter((city) => city.i)
64
66
  .map((city) => ({ iso: city.i, name: city.n }));
65
67
  };
66
68
  exports.cities_by_continent = cities_by_continent;
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.states_by_continent = exports.states_by_country = exports.states = void 0;
7
7
  const en_json_1 = __importDefault(require("../data/en.json"));
8
8
  // States
9
- const states = () => en_json_1.default.flatMap((continent) => continent.cn.flatMap((country) => country.s || [])).map(state => ({ iso: state.i, name: state.n }));
9
+ const states = () => en_json_1.default.flatMap((continent) => continent.cn.flatMap((country) => country.s || [])).filter((state) => state.i).map((state) => ({ iso: state.i, name: state.n }));
10
10
  exports.states = states;
11
11
  const states_by_country = (iso) => {
12
12
  for (const continent of en_json_1.default) {
13
13
  const country = continent.cn.find(c => c.i === iso);
14
14
  if (country?.s) {
15
- return country.s.map((state) => ({ iso: state.i, name: state.n }));
15
+ return country.s.filter((state) => state.i).map((state) => ({ iso: state.i, name: state.n }));
16
16
  }
17
17
  }
18
18
  return [];
@@ -24,6 +24,7 @@ const states_by_continent = (iso) => {
24
24
  return [];
25
25
  return continent.cn
26
26
  .flatMap((country) => country.s || [])
27
- .map(state => ({ iso: state.i, name: state.n }));
27
+ .filter((state) => state.i)
28
+ .map((state) => ({ iso: state.i, name: state.n }));
28
29
  };
29
30
  exports.states_by_continent = states_by_continent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "countries-geo",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "description": "Library for fetching Continents, Countries, States and its Cities",
6
6
  "license": "MIT",