JSPM

  • Created
  • Published
  • Downloads 114468
  • Score
    100M100P100Q155163F

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

tld.js is available under NPM registry.

npm install tldjs --save --production

And to include it in any relevant script:

var tld = require('tldjs');

getDomain()

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`

isValid()

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

Updating 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.

You may have installed the package with its devDependencies with:

npm install tldjs --save

If you did not install with the --production flag, then it's okay.

grunt is mandatory to build and update rules. If it's not installed globally, then do so:

npm install -g grunt

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.