Giter VIP home page Giter VIP logo

node-tld's Introduction

Build Status Coverage Status Version License Code style

Motivation

Extract the TLD/domain/subdomain parts of an URL/hostname against mozilla TLDs official listing.

API

var parser = require('tld-extract');

console.log( parser("http://www.google.com") );
console.log( parser("http://google.co.uk") );
/**
* >> { tld: 'com', domain: 'google.com', sub: 'www' }
* >> { tld: 'co.uk', domain: 'google.co.uk', sub: '' }
*/

Private TLDs

Private TLDs are supported, see chromium source code for specs

console.log( parser("http://jeanlebon.cloudfront.net"));
/**
* >> { tld : 'net', domain : 'cloudfront.net', sub : 'jeanlebon' };
*/


console.log( parser("http://jeanlebon.cloudfront.net", {allowPrivateTLD : true}));
/**
* >> { tld : 'cloudfront.net', domain : 'jeanlebon.cloudfront.net', sub : '' };
*/

Unknown TLDs (level0)

By default, unknown TLD throw an exception, you can allow them and use tld-extract as a parser using the allowUnknownTLD option

  parse("http://nowhere.local")
    >> throws /Invalid TLD/

  parse("http://nowhere.local", {allowUnknownTLD : true}))
    >> { tld : 'local', domain : 'nowhere.local', sub : '' }

Why

  • no dependencies
  • really fast
  • full code coverage
  • easy to read (10 lines)
  • easily updatable vs mozilla TLDs source list

Maintenance

You can update the remote hash table using npm run update

Not Invented Here

  • A port of a yks/PHP library

  • tldextract => bad API, (no need for async, "domain" property is wrong), no need for dependencies

  • tld => (nothing bad, a bit outdated )

  • tld.js => no sane way to prove/trust/update TLD listing

Credits

node-tld's People

Contributors

131 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.