( url: string | null | undefined, fallback = "" )
| 395 | * Falls back to the provided value when the URL is not a github.com profile. |
| 396 | */ |
| 397 | export function getGitHubHandle( |
| 398 | url: string | null | undefined, |
| 399 | fallback = "" |
| 400 | ): string { |
| 401 | if (!url) return fallback; |
| 402 | try { |
| 403 | const parsed = new URL(url); |
| 404 | const host = parsed.hostname.replace(/^www\./, ""); |
| 405 | if (host === "github.com") { |
| 406 | const segments = parsed.pathname.split("/").filter(Boolean); |
| 407 | if (segments.length === 1) { |
| 408 | return `@${segments[0]}`; |
| 409 | } |
| 410 | } |
| 411 | } catch { |
| 412 | // Invalid URL |
| 413 | } |
| 414 | return fallback; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Truncate text with ellipsis |
no outgoing calls
no test coverage detected