UNPKG

@octopusdeploy/design-system-components

Version:
26 lines (25 loc) 732 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatExternalUrl = formatExternalUrl; function formatExternalUrl(href) { if (parseUrl(href)) { return href; } return "https://oc.to/" + href; } function parseUrl(url) { try { // We need these .startsWith checks because IE11 will assume URL("someString") is relative to the current // domain and won't throw (like every other browser in the universe). if (url.startsWith("http://") || url.startsWith("https://")) { const ignored = new URL(url); return true; } else { return false; } } catch (error) { return false; } }