countries-geo 0.0.4 → 0.0.5

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/dist/states.d.ts CHANGED
@@ -2,12 +2,12 @@ declare const _default: {
2
2
  getAll: import("./utils/interface").TState[];
3
3
  sortByIsoCode: import("./utils/interface").TState[];
4
4
  getByCountry: (iso: string) => {
5
- iso: string;
6
- name: string;
5
+ iso: any;
6
+ name: any;
7
7
  }[];
8
8
  getByContinent: (iso: string) => {
9
- iso: string;
10
- name: string;
9
+ iso: any;
10
+ name: any;
11
11
  }[];
12
12
  };
13
13
  export default _default;
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  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
- const data_json_1 = __importDefault(require("../data.json"));
7
+ const en_json_1 = __importDefault(require("../data/en.json"));
8
8
  // Cities
9
- const cities = () => data_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 || []).map(city => ({ iso: city.i, name: city.n }));
10
10
  exports.cities = cities;
11
11
  const cities_by_state = (iso) => {
12
12
  try {
@@ -16,9 +16,9 @@ const cities_by_state = (iso) => {
16
16
  }
17
17
  const [countryIso, stateIso] = iso.split('-');
18
18
  // Safely traverse the data structure
19
- if (!data_json_1.default || !Array.isArray(data_json_1.default))
19
+ if (!en_json_1.default || !Array.isArray(en_json_1.default))
20
20
  return [];
21
- for (const continent of data_json_1.default) {
21
+ for (const continent of en_json_1.default) {
22
22
  if (!continent.cn || !Array.isArray(continent.cn))
23
23
  continue;
24
24
  for (const country of continent.cn) {
@@ -26,10 +26,10 @@ const cities_by_state = (iso) => {
26
26
  // Check if states exist and are iterable
27
27
  if (!country.s || !Array.isArray(country.s))
28
28
  return [];
29
- const state = country.s.find(s => s.i === stateIso);
29
+ const state = country.s.find((s) => s.i === stateIso);
30
30
  // Check if cities exist and are iterable
31
31
  if (state?.c && Array.isArray(state.c)) {
32
- return state.c.map(city => ({
32
+ return state.c.map((city) => ({
33
33
  iso: `${countryIso}-${stateIso}-${city.i}`,
34
34
  name: city.n
35
35
  }));
@@ -47,20 +47,20 @@ const cities_by_state = (iso) => {
47
47
  };
48
48
  exports.cities_by_state = cities_by_state;
49
49
  const cities_by_country = (iso) => {
50
- return data_json_1.default
51
- .flatMap(continent => continent.cn)
50
+ return en_json_1.default
51
+ .flatMap((continent) => continent.cn)
52
52
  .find(country => country.i === iso)
53
- ?.s?.flatMap(state => state.c || [])
54
- ?.map(city => ({ iso: city.i, name: city.n })) || [];
53
+ ?.s?.flatMap((state) => state.c || [])
54
+ ?.map((city) => ({ iso: city.i, name: city.n })) || [];
55
55
  };
56
56
  exports.cities_by_country = cities_by_country;
57
57
  const cities_by_continent = (iso) => {
58
- const continent = data_json_1.default.find(c => c.i === iso);
58
+ const continent = en_json_1.default.find(c => c.i === iso);
59
59
  if (!continent)
60
60
  return [];
61
61
  return continent.cn
62
- .flatMap(country => country.s || [])
63
- .flatMap(state => state.c || [])
64
- .map(city => ({ iso: city.i, name: city.n }));
62
+ .flatMap((country) => country.s || [])
63
+ .flatMap((state) => state.c || [])
64
+ .map((city) => ({ iso: city.i, name: city.n }));
65
65
  };
66
66
  exports.cities_by_continent = cities_by_continent;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.continents = void 0;
7
- const data_json_1 = __importDefault(require("../data.json"));
7
+ const en_json_1 = __importDefault(require("../data/en.json"));
8
8
  // Continents
9
- const continents = () => data_json_1.default?.map(({ i, n }) => ({ iso: i, name: n }));
9
+ const continents = () => en_json_1.default?.map(({ i, n }) => ({ iso: i, name: n }));
10
10
  exports.continents = continents;
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.countries_by_continent = exports.countries = void 0;
7
- const data_json_1 = __importDefault(require("../data.json"));
7
+ const en_json_1 = __importDefault(require("../data/en.json"));
8
8
  // Countries
9
- const countries = () => data_json_1.default?.flatMap(continent => continent?.cn?.map(country => ({ iso: country.i, name: country.n })));
9
+ const countries = () => en_json_1.default?.flatMap(continent => continent?.cn?.map(country => ({ iso: country.i, name: country.n })));
10
10
  exports.countries = countries;
11
11
  const countries_by_continent = (iso) => {
12
- const continent = data_json_1.default?.find(c => c.i === iso);
12
+ const continent = en_json_1.default?.find(c => c.i === iso);
13
13
  if (!continent)
14
14
  return [];
15
15
  return continent?.cn?.map(country => ({
@@ -1,10 +1,10 @@
1
1
  import { TState } from './interface';
2
2
  export declare const states: () => TState[];
3
3
  export declare const states_by_country: (iso: string) => {
4
- iso: string;
5
- name: string;
4
+ iso: any;
5
+ name: any;
6
6
  }[];
7
7
  export declare const states_by_continent: (iso: string) => {
8
- iso: string;
9
- name: string;
8
+ iso: any;
9
+ name: any;
10
10
  }[];
@@ -4,26 +4,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.states_by_continent = exports.states_by_country = exports.states = void 0;
7
- const data_json_1 = __importDefault(require("../data.json"));
7
+ const en_json_1 = __importDefault(require("../data/en.json"));
8
8
  // States
9
- const states = () => data_json_1.default.flatMap(continent => continent.cn).map(state => ({ iso: state.i, name: state.n }));
9
+ const states = () => en_json_1.default.flatMap((continent) => continent.cn.flatMap((country) => country.s || [])).map(state => ({ iso: state.i, name: state.n }));
10
10
  exports.states = states;
11
11
  const states_by_country = (iso) => {
12
- for (const continent of data_json_1.default) {
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.map((state) => ({ iso: state.i, name: state.n }));
16
16
  }
17
17
  }
18
18
  return [];
19
19
  };
20
20
  exports.states_by_country = states_by_country;
21
21
  const states_by_continent = (iso) => {
22
- const continent = data_json_1.default.find(c => c.i === iso);
22
+ const continent = en_json_1.default.find(c => c.i === iso);
23
23
  if (!continent)
24
24
  return [];
25
25
  return continent.cn
26
- .flatMap(country => country.s || [])
26
+ .flatMap((country) => country.s || [])
27
27
  .map(state => ({ iso: state.i, name: state.n }));
28
28
  };
29
29
  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.4",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "description": "Library for fetching Continents, Countries, States and its Cities",
6
6
  "license": "MIT",