JavaScript Tldextract (Extract Host From URL)

tld-extract

tld-extract

Install

npm i tld-extract

Usage

const parser = require('tld-extract')const part = parser('http://www.google.com') // { tld: 'com', domain: 'google.com', sub: 'www' }

NOTE: tld-extract library size is pretty big

URL

const url = 'http://www.google.com'const part = new URL(url)
{
  hash: ""
  host: "www.google.com"
  hostname: "www.google.com"
  href: "http://www.google.com/"
  origin: "http://www.google.com"
  password: ""
  pathname: "/"
  port: ""
  protocol: "http:"
  search: ""
  searchParams: URLSearchParams {}
  username: ""
}

NOTE: Refer URL. host will include port if specified.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.