Skip to content

Instantly share code, notes, and snippets.

@martinratinaud
Last active August 3, 2021 09:02
Show Gist options
  • Save martinratinaud/38bab1e0620cbadba2bd13b582aef74f to your computer and use it in GitHub Desktop.
Save martinratinaud/38bab1e0620cbadba2bd13b582aef74f to your computer and use it in GitHub Desktop.
Extract domain name without subdomain from any url in javascript
const extractDomainName = (url:string) => {
const [extension, domain] = new URL(url).hostname.split('.').reverse();
return `${domain}.${extension}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment