country-state-city-js
Version:
A fast & light weight JS library to get countries geographical information including states, cities, iso codes, etc.
31 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CountryLite = exports.Country = void 0;
var utils_1 = require("../utils");
exports.Country = countryHandler();
exports.CountryLite = countryHandler('lite');
function countryHandler(type) {
var path = type === 'lite' ? utils_1.PATH_LITE : utils_1.PATH;
var fn = function (countryIso2, populate) {
if (!countryIso2 || typeof countryIso2 == 'object') {
var countries = [];
for (var _i = 0, countryDir_1 = utils_1.countryDir; _i < countryDir_1.length; _i++) {
var code = countryDir_1[_i];
var country = require(path + "/countries/" + code + "/index.json");
(0, utils_1.populateStatesCities)(country, countryIso2, type);
countries.push(country);
}
return countries;
}
try {
var country = require(path + "/countries/" + countryIso2 + "/index.json");
(0, utils_1.populateStatesCities)(country, populate, type);
return country !== null && country !== void 0 ? country : null;
}
catch (e) {
return null;
}
};
return fn;
}
//# sourceMappingURL=country.js.map