I am trying to create a javascript function that can extract only the 'domain' and 'top-level domain' from a url string.
The current questions on StackOverFlow do not resolve the answer for non-urls too.
Examples:
- https://www.google.com/imgres?imgurl -> google.com
- yahoo.com/mail -> yahoo.com
- http://helloworld.net/index/test/help -> helloworld.net
- www.stackoverflow.com/ -> stackoverflow.com
- invalid.url -> "return false or an empty string"
Any/All help is welcome and appreciated. Thank you.