{"comment":{"url":"https://api.github.com/repos/moshmage/voat/comments/11698210","html_url":"https://github.com/moshmage/voat/commit/f28dfe330fd587576b862f2aaefc3bb027a71107#commitcomment-11698210","id":11698210,"user":{"login":"deltaidea","id":4950036,"avatar_url":"https://avatars.githubusercontent.com/u/4950036?v=3","gravatar_id":"","url":"https://api.github.com/users/deltaidea","html_url":"https://github.com/deltaidea","followers_url":"https://api.github.com/users/deltaidea/followers","following_url":"https://api.github.com/users/deltaidea/following{/other_user}","gists_url":"https://api.github.com/users/deltaidea/gists{/gist_id}","starred_url":"https://api.github.com/users/deltaidea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deltaidea/subscriptions","organizations_url":"https://api.github.com/users/deltaidea/orgs","repos_url":"https://api.github.com/users/deltaidea/repos","events_url":"https://api.github.com/users/deltaidea/events{/privacy}","received_events_url":"https://api.github.com/users/deltaidea/received_events","type":"User","site_admin":false},"position":8,"line":72,"path":"Whoaverse/Whoaverse/Scripts/whoaverse.ui.js","commit_id":"f28dfe330fd587576b862f2aaefc3bb027a71107","created_at":"2015-06-16T09:32:27Z","updated_at":"2015-06-16T09:32:27Z","body":"It returns only the TLD when `removeSub` is `true` in the given example. I don't see the point of knowing TLD.  \r\nBut it somewhy passes the following test, which is confusing:\r\n\r\n```JavaScript\r\nit('should remove subdomains, but not second level domain', function (done) {\r\n    getDomainName(\"http://whatever.long.example.com/test\",true,false,false).\r\n        should.be.equal('http://example.com/test');\r\n    done();\r\n});\r\n```\r\n\r\nIt also doesn't pass the following tests:\r\n\r\n```JavaScript\r\nit('should remove path with multiple levels', function (done) {\r\n    getDomainName(\"https://voat.co/v/all/new\",false,false,true).\r\n        should.be.equal('https://voat.co');\r\n    done();\r\n});\r\n\r\nit('should remove https', function (done) {\r\n    getDomainName(\"https://voat.co/v/all/new\",false,true,false).\r\n        should.be.equal('voat.co/v/all/new');\r\n    done();\r\n});\r\n\r\nit('should remove https and path with multiple levels', function (done) {\r\n    getDomainName(\"https://voat.co/v/all/new\",false,true,false).\r\n        should.be.equal('voat.co');\r\n    done();\r\n});\r\n```\r\n\r\nI would recommend using [the following function](https://gist.github.com/jlong/2428561) instead:\r\n\r\n```JavaScript\r\nvar parser = document.createElement('a');\r\nparser.href = \"http://example.com:3000/pathname/?search=test#hash\";\r\n \r\nparser.protocol; // => \"http:\"\r\nparser.hostname; // => \"example.com\"\r\nparser.port;     // => \"3000\"\r\nparser.pathname; // => \"/pathname/\"\r\nparser.search;   // => \"?search=test\"\r\nparser.hash;     // => \"#hash\"\r\nparser.host;     // => \"example.com:3000\"\r\n```\r\n\r\nThanks!"}}