( handleOrUrl: string | null )
| 27 | * @returns Twitter URL. |
| 28 | */ |
| 29 | export const normalizeTwitter = ( |
| 30 | handleOrUrl: string | null |
| 31 | ): string | undefined => { |
| 32 | if (!handleOrUrl) return undefined; |
| 33 | |
| 34 | let url; |
| 35 | try { |
| 36 | new URL(handleOrUrl); |
| 37 | } catch { |
| 38 | url = `https://x.com/${handleOrUrl.replace(/^@/, '')}`; |
| 39 | } |
| 40 | return url ?? handleOrUrl; |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * Converts a Bluesky handle or URL to a URL. |
no outgoing calls
no test coverage detected