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');
Private TLDs
Private TLDs are supported:
import { parseUrl } from 'extract-tld';
parseUrl('test.compute.amazonaws.com', { allowPrivateTLD: true });
Unknown TLDs
You can allow unknown TLDs by specifying the configuration option:
import { parseUrl } from 'extract-tld';
parseUrl('https://somewhere.local');
parseUrl('https://somewhere.local', { allowUnknownTLD: true });
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.