JSPM

  • Created
  • Published
  • Downloads 108086
  • Score
    100M100P100Q152587F

Handful API to do stuff with domain names and URIs: validity, public etc.

Package Exports

  • tldjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tldjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

tld.js

Build Status

Handful API to do stuff with domain names and URIs: validity, public etc.

Its main purpose is to check if a domain name is valid upon. 2 constraints:

  • an up-to-date TLDs database
  • must work in node.js and the browser

It is based on the public suffix list provided by Mozilla. Thanks Mozilla!

Usage

isValid()

var tld = require('tld');

tld.isValid('google.com'); // returns `true`
tld.isValid('t.co'); // returns `true`
tld.isValid('t.go'); // returns `false`

getDomain()

var tld = require('tld');

tld.getDomain('google.com'); // returns `google.com`
tld.getDomain('fr.google.com'); // returns `google.com`
tld.getDomain('google.co.uk'); // returns `google.co.uk`
tld.getDomain('foo.google.co.uk'); // returns `google.co.uk`
tld.getDomain('t.co'); // returns `t.co`
tld.getDomain('fr.t.co'); // returns `t.co`

Browser-side

Notice: this part has not been developed yet.

The library is designed to be useable on the browser-side, in an framework agnostic fashion. No jQuery.tld().

<script src="/path/to/tld.js"></script>
<script>
tld.getDomain(window.location.host); //returns the current domain
</script>

Rebuilding TLDs List

Many libraries offer a list of TLDs. But, are they up-to-date? And how to update them?

Hopefully for you, even if I'm flying over the world, if I've lost my Internet connection or even if you do manage your own list, you can update it by yourself, painlessly.

How? By typing this in your console

npm run-script build

A fresh copy will be located in src/rules.json.

Contributing

Provide a pull request (with tested code) to include your work in this main project. Issues may be awaiting for help so feel free to give a hand, with code or ideas.