import { countryType, returnT, CityFnType } from "../types" import { PATH, PATH_LITE } from "../utils" export const City: CityFnType = cityHandler() export const CityLite: CityFnType = cityHandler('lite') function cityHandler(type?: 'lite'): CityFnType { const fn: CityFnType = function (cointryIso2: countryType, stateIso: string): returnT { if (!cointryIso2) { throw new TypeError("Country iso2 type missing") } if (!stateIso) { throw new TypeError("State iso type missing") } try { return require(`${type === 'lite' ? PATH_LITE : PATH}/cities/${cointryIso2}/${stateIso}/index.json`) } catch (e) { return [] } } return fn }