Last active
August 3, 2021 09:02
-
-
Save martinratinaud/38bab1e0620cbadba2bd13b582aef74f to your computer and use it in GitHub Desktop.
Extract domain name without subdomain from any url in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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