Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extract-tld

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-tld

Extract the TLD from a URL against the [public suffix list](https://publicsuffix.org/).

  • 1.0.5
  • npm
  • Socket score

Version published
Weekly downloads
175
decreased by-73.6%
Maintainers
1
Weekly downloads
 
Created
Source

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 :)

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.

Keywords

FAQs

Package last updated on 11 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc