Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WEB-4881] feat(utils): add URL display formatter #7770

Vihar Kuramae891482a9783
diff --git a/packages/utils/src/url.ts b/packages/utils/src/url.ts
index 738d935d5c..0321cec4d2 100644
--- a/packages/utils/src/url.ts
+++ b/packages/utils/src/url.ts
@@ -97,6 +97,24 @@ export function extractHostname(url: string): string {
return hostname;
}
+/**
+ * Returns a readable representation of a URL by stripping the protocol
+ * and any trailing slash. For valid URLs, only the host is returned.
+ * Invalid URLs are sanitized by removing the protocol and trailing slash.
+ *
+ * @param url - The URL string to format
+ * @returns The formatted domain for display
+ */
+export function formatURLForDisplay(url: string): string {
+ if (!url) return "";
+
+ try {
+ return new URL(url).host;
+ } catch (_error) {
+ return extractHostname(url);
+ }
+}
+
/**
* Extracts and validates the TLD (Top Level Domain) from a URL string.
*