tld.js

Open source

A JavaScript library to work easily with complex domain names, subdomains and well-known TLDs.

Become a contributor

Financial contributions

Custom contribution

Donation

Make a custom one time or recurring contribution to support this collective.
Recurring contribution

Companies

Consider this if your company uses tld.js for one or many products. Your logo+link to your websi... Read more

Starts at

$100 USD / year

tld.js is all of us

Our contributors 2

Everyone who has supported tld.js. Individuals and organizations that believe in –and take ownership of– our purpose.

Thomas Parisot
Collective Admin
Rémi
Collective Admin

About

It answers with accuracy to questions like what is mail.google.com's domain?, what is a.b.ide.kyoto.jp's subdomain? and is https://big.data's TLD a well-known one?.

tld.js runs fast, is fully tested and is safe to use in the browser (with browserify, webpack and others). Because it relies on Mozilla's public suffix list, now is a good time to say thank you Mozilla!

Install

npm install

Using It

const {parse, tldExists} = require('tldjs');

// Checking only if TLD exists in URL or hostname
// First TLD exists; the second does not.
console.log(tldExists('https://www.bbc'));
console.log(tldExists('tld.unknown'));

// Retrieving hostname related informations of a given URL
parse('https://opencollective.com/tldjs');

This project is used by many projects such as Brave authorship programme, Help.com, Standuply and Ghost.

Reverse-Support

Because this project relies on Mozilla Public Suffix project, it would be sensible that a fare share of our donations goes back to them.