get the tld (top-level-domain) from a url
for component:
$ component install ramitos/tld.js
for node.js:
$ npm install tld.js
with string url:
var tld = require('tld.js')
tld('http://www.example.co.uk') //=> co.ukwith parsed url:
var tld = require('tld.js'),
url = require('url')
tld(url.parse('http://www.example.co.uk')) //=> co.ukThe node.js url parser is different from the browser url parser. So, the browser has 2 cases where the parsing is not correct:
scheme://user:pass@www.example.org:123/some/directory/file.html?query=string#fragmentshould returnorgand returns nothingmailto:hello@example.org?subject=helloshould returnorgand returns nothing
This two cases are covered in the tests and fail in the browser tests
$ npm test
- inspired by URI.js where the second-level-domain regular expression comes from
MIT
