
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
extract-tld
Advanced tools
Extract the TLD from a URL against the [public suffix list](https://publicsuffix.org/).
Extract the TLD from a URL against the public suffix list.
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' }
import { parseUrl } from 'extract-tld';
parseUrl('test.compute.amazonaws.com', { allowPrivateTLD: true });
// { domain: 'test.compute.amazonaws.com', sub: '', tld: 'compute.amazonaws.com' }
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' }
Ensure you have pnpm installed
pnpm install
All contributions are welcome - feel free to open a PR or issue :)
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.
FAQs
Extract the TLD from a URL against the [public suffix list](https://publicsuffix.org/).
We found that extract-tld demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.