We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bedc1fa commit e891482Copy full SHA for e891482
1 file changed
packages/utils/src/url.ts
@@ -97,6 +97,24 @@ export function extractHostname(url: string): string {
97
return hostname;
98
}
99
100
+/**
101
+ * Returns a readable representation of a URL by stripping the protocol
102
+ * and any trailing slash. For valid URLs, only the host is returned.
103
+ * Invalid URLs are sanitized by removing the protocol and trailing slash.
104
+ *
105
+ * @param url - The URL string to format
106
+ * @returns The formatted domain for display
107
+ */
108
+export function formatURLForDisplay(url: string): string {
109
+ if (!url) return "";
110
+
111
+ try {
112
+ return new URL(url).host;
113
+ } catch (_error) {
114
+ return extractHostname(url);
115
+ }
116
+}
117
118
/**
119
* Extracts and validates the TLD (Top Level Domain) from a URL string.
120
*
0 commit comments