@butlerbot/sdk
Version:
The official ButlerBot SDK
19 lines (18 loc) • 747 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatURL = formatURL;
function formatURL(url, params = {}, config) {
const fParams = Object.assign({ api_key: config.apiKey }, params);
const paramQuery = new URLSearchParams(fParams).toString();
const fUrl = `${url}?${paramQuery}`;
if (config.debug) {
const debugUrl = new URL(fUrl);
const apiKey = debugUrl.searchParams.get('api_key');
if (apiKey) {
const obscuredKey = apiKey.length > 6 ? `${apiKey.slice(0, 3)}...${apiKey.slice(-3)}` : '***';
debugUrl.searchParams.set('api_key', obscuredKey);
}
console.log(`[Formatting URL ${debugUrl.toString()}]`);
}
return fUrl;
}