Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
/ tld.js Public archive

get the tld from a (parsed) url

Notifications You must be signed in to change notification settings

sergioramos/tld.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tld.js

get the tld (top-level-domain) from a url

installation

for component:

$ component install ramitos/tld.js

for node.js:

$ npm install tld.js

usage

with string url:

var tld = require('tld.js')

tld('http://www.example.co.uk') //=> co.uk

with parsed url:

var tld = require('tld.js'),
    url = require('url')

tld(url.parse('http://www.example.co.uk')) //=> co.uk

to be aware

The 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:[email protected]:123/some/directory/file.html?query=string#fragment should return org and returns nothing
  • mailto:[email protected]?subject=hello should return org and returns nothing

This two cases are covered in the tests and fail in the browser tests

test Build Status

$ npm test

credits

  • inspired by URI.js where the second-level-domain regular expression comes from

license

MIT

About

get the tld from a (parsed) url

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published