export function getDomain(url: string, subdomain?: string, publicSuffix?: string): string { let updatedUrl: any = url.replace(/(https?:\/\/)?(www.)?/i, '') if (!subdomain) { if (publicSuffix) { const updatedPublicSuffix = publicSuffix.startsWith('.') ? publicSuffix : '.' + publicSuffix updatedUrl = url.replace(updatedPublicSuffix, '').split('.') updatedUrl = updatedUrl.length > 0 ? updatedUrl[updatedUrl.length - 1] : '' updatedUrl += updatedPublicSuffix } else { updatedUrl = updatedUrl.split(".") updatedUrl = updatedUrl.slice(updatedUrl.length - 2).join(".") } } if (updatedUrl.indexOf('/') !== -1) { return updatedUrl.split('/')[0] } return updatedUrl }