-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Overview
Create utility to extract domain from story URLs.
Parent Epic: #70
Priority: P2
Prerequisites
- 1.3: Set Up TypeScript Configuration #73 (1.3: Set Up TypeScript Configuration)
Next Issues (after this is complete)
- Can be used by Story component
Acceptance Criteria
-
app/javascript/lib/urlUtils.tscreated - Extracts domain from full URLs
- Handles edge cases (no URL, malformed URL, no protocol)
- Strips "www." prefix
- Unit tests with Jest/Vitest
- TypeScript types exported
Implementation Notes
export function extractDomain(url: string | null | undefined): string | null {
if (!url) return null;
try {
const parsed = new URL(url);
return parsed.hostname.replace(/^www\./, '');
} catch {
return null;
}
}
// Examples:
// "https://www.example.com/path" -> "example.com"
// "http://github.com/user/repo" -> "github.com"
// null -> null
// "not a url" -> nullNote: This could also be done server-side in the Story presenter.
coderabbitai