You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@thoughtindustries/tldextract

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thoughtindustries/tldextract

Extract domain, subdomain and tld from a url

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
286
12.16%
Maintainers
1
Weekly downloads
 
Created
Source

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('@thoughtindustries/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.

Keywords

url

FAQs

Package last updated on 19 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts