UNPKG

nigerian-state-city-selector

Version:

nigerian-state-city-selector

27 lines (26 loc) 824 B
import * as countryData from "./data/country.json"; import * as stateData from "./data/state.json"; import * as cityData from "./data/city.json"; export class CountryStateCitySelector { constructor() { this.currentCountry = null; this.currentState = null; this.countryList = countryData.data; this.stateList = stateData.data; this.cityList = cityData.data; } getStates() { return this.stateList; } // Select a state by its Name selectState(stateName) { const state = this.stateList.filter((s) => s.name === stateName)[0]; this.currentState = state; } getCities() { if (!this.currentState) { return []; } return this.cityList.filter((city) => city.state_id === this.currentState?.id); } }