The Manage screen reduces instance URLs to the hostname, and Home Assistant uses the integration name as its title with the instance name as byline.
17 lines
436 B
JavaScript
17 lines
436 B
JavaScript
// Instance URLs are shown as bylines, where only the host identifies the
|
|
// instance. Keep the stored URL intact for network calls and reduce it to the
|
|
// hostname only for display.
|
|
export function displayHost(url) {
|
|
if (typeof url !== 'string' || !url) {
|
|
return '';
|
|
}
|
|
|
|
const value = /^[a-z][a-z0-9+.-]*:\/\//i.test(url) ? url : `https://${url}`;
|
|
|
|
try {
|
|
return new URL(value).hostname;
|
|
} catch {
|
|
return '';
|
|
}
|
|
}
|