Git Product home page Git Product logo

extract-tld's Introduction

extract-tld

Extract the TLD from a URL against the public suffix list.

Getting started

Install the package using your preferred package manager:

npm install extract-tld

You can now use the parser:

import { parseUrl } from 'extract-tld';

parseUrl('https://google.com');
// { domain: 'google.com', sub: 'https://www', tld: 'com' }

Private TLDs

Private TLDs are supported:

import { parseUrl } from 'extract-tld';

parseUrl('test.compute.amazonaws.com', { allowPrivateTLD: true });
// { domain: 'test.compute.amazonaws.com', sub: '', tld: 'compute.amazonaws.com' }

Unknown TLDs

You can allow unknown TLDs by specifying the configuration option:

import { parseUrl } from 'extract-tld';

parseUrl('https://somewhere.local');
// Throws

parseUrl('https://somewhere.local', { allowUnknownTLD: true });
// { domain: 'http://somewhere.local', sub: '', tld: 'local' }

Development

Ensure you have pnpm installed

  • Clone this repository
  • Run pnpm install

Contributing

All contributions are welcome - feel free to open a PR or issue :)

List maintenance

There is a script that will fetch the latest public suffix list and transform it into a format usable by this library. You can run the script by running pnmpm updateList.

Ideally, this script would run once a day and update tlds.json accordingly, but the work for that hasn't been done yet.

Credits

  • tld-extract
    • This is the main basis of inspiration for this library. I've basically taken this library and modernised it (and added some nice things like TypeScript support) as the author seems to be unreachable.

extract-tld's People

Contributors

grug avatar

Stargazers

James Benner avatar

Watchers

 avatar  avatar

Forkers

paul-asvb

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.