Skip to content

jtwebb/tldextract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tldextract

Forked from https://github.com/masylum/tldextract

Accurately separates the gTLD or ccTLD (generic or country code top-level domain) from the registered domain and subdomains of a URL.

How does it work?

const tldExtract = require('@jtwebb/tldextract');

try {
  const data1 = tldExtract('https://forums.news.cnn.com/');
  // data1 = { subdomain: 'forums.news', domain: 'cnn', tld: 'com' }
    
  const data2 = tldExtract('https://forums.news.cnn.com/');
  // data2 = { subdomain: 'ye', domain: 'ye', tld: 'ye.ye' }
} catch (e) {
  // e.message === 'No domain/IP detected' if there is an error
  console.error(e);
}

tests

npm run test

Disclaimer

This module is a port of the python module tldextract.

About

Extract domain, subdomain and tld from a url

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published