@contiva/sap-integration-suite-client
Version:
SAP Cloud Platform Integration API Client
30 lines (29 loc) • 854 B
JavaScript
;
/**
* Utility for extracting hostname from URLs
*
* @module hostname-extractor
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractHostname = extractHostname;
/**
* Extracts the hostname from a base URL
*
* @param baseUrl - The base URL to extract hostname from
* @returns The hostname without protocol and path
*
* @example
* extractHostname('https://tenant.integrationsuitetrial-api.eu10.hana.ondemand.com/api/v1')
* // Returns: 'tenant.integrationsuitetrial-api.eu10.hana.ondemand.com'
*/
function extractHostname(baseUrl) {
try {
const url = new URL(baseUrl);
return url.hostname;
}
catch (_a) {
// Fallback: try to extract hostname manually
const match = baseUrl.match(/(?:https?:\/\/)?([^\/]+)/);
return match ? match[1] : baseUrl;
}
}