/** * Extract a Vimeo numeric `videoId` from a URL. * * Supports: * - vimeo.com/123456789 * - vimeo.com/123456789/HASH * - player.vimeo.com/video/123456789 * * Returns `null` if the URL does not match. */ export function extractVimeoId(input: string): string | null { let url: URL; try { url = new URL(input); } catch { return null; } const host = url.hostname.replace(/^www\./, ''); if (host !== 'vimeo.com' && host !== 'player.vimeo.com') return null; // /video/ on player.vimeo.com, / on vimeo.com. const match = url.pathname.match(/(?:^\/video\/|^\/)(\d+)/); return match ? match[1] : null; }