How to get the root domain name from a given URL in javascript without the extension?
Example:
rootDomain("https://www.etsy.com/market/tumblr_clothing")
-> etsy
rootDomain("https://petitions.whitehouse.gov/")
-> whitehouse
rootDomain("facebook.com")
-> facebook
rootDomain("google.ca")
-> google
I was able to find a incomplete solution: How to get domain name only using javascript? and Extract hostname name from string
The main problem is that I'm having trouble creating a solution without the extension or subdomain.
How would be the best way to tackle this?