barikoiapis
Version:
Bangladeshi location data provider API library from barikoi.com
34 lines • 1.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.autocomplete = void 0;
const config_1 = require("./config");
const axios_1 = __importDefault(require("axios"));
async function autocomplete(options) {
const apiKey = (0, config_1.getConfig)().apiKey;
const version = (0, config_1.getConfig)().version;
let apiUrl = '';
if (version === 'v2') {
apiUrl = `https://barikoi.xyz/v2/api/search/autocomplete/place`;
}
else {
apiUrl = `https://barikoi.xyz/v1/api/search/autocomplete/${apiKey}/place`;
}
const params = version === 'v1' ? { ...options } : { api_key: apiKey, ...options };
try {
const response = await axios_1.default.get(apiUrl, {
params,
});
// Return the full `data` object from the response
return response.data;
}
catch (error) {
// Handle errors, log them, or throw an exception
console.error('Autocomplete request failed:', error.message);
throw error;
}
}
exports.autocomplete = autocomplete;
//# sourceMappingURL=autocomplete.js.map