Skip to content

Commit

Permalink
fix dynamic import issue v2
Browse files Browse the repository at this point in the history
  • Loading branch information
hendurhance committed Apr 16, 2024
1 parent ebdab8b commit e375d65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplifiedhq/countries-atlas",
"version": "1.2.2",
"version": "1.2.3",
"description": "Uncover the world with a single lightweight library - countries, codes, currencies, flags, languages, cities, and more 🌎",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
38 changes: 6 additions & 32 deletions src/helpers/CountriesAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,23 @@ export class CountriesAtlas {
return this.countries.find(country => country.iso3?.toUpperCase() === iso3.toUpperCase())
}

// getStates(iso2: string): Promise<State[]> | undefined {
// const country = this.find(iso2)
// if (country) {
// return import(`../data/countries/${country.iso2?.toLowerCase()}.json`)
// .then(statesData => {
// return statesData.states
// })
// .catch(() => {
// return undefined
// })
// }
// return undefined
// }

/**
* Retrieve all states of a country by its ISO2 code.
*
* @param {string} iso2 - ISO2 code of the country.
* @returns {State[] | undefined} - Array of state objects or undefined if not found.
* @returns {Promise<State[]> | undefined} - Array of state objects or undefined if not found.
*/
getStates(iso2: string): State[] | undefined {
getStates(iso2: string): Promise<State[] | undefined> | undefined {
const country = this.find(iso2)
if (country) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const statesData = require(`../data/countries/${country.iso2?.toLowerCase()}.json`)
return statesData.states
const stateData = import(`../data/countries/${country.iso2?.toLowerCase()}.json`)
return stateData.then((statesData: StateData) => {
return statesData.states
});
}
return undefined
}

// state(iso2: string, stateCode: string): Promise<State | undefined> | undefined {
// const country = this.find(iso2);
// if (country) {
// return import(`../data/countries/${country.iso2?.toLowerCase()}.json`)
// .then((statesData: StateData) => {
// const state = statesData.states.find((s: State) => s.state_code?.toUpperCase() === stateCode);
// return state ? state : undefined;
// })
// .catch(() => undefined);
// }
// return undefined;
// }

/**
* Find a state by its state code and country ISO2 code.
*
Expand Down

0 comments on commit e375d65

Please sign in to comment.