tldts
tldts: Fast Domain, Subdomain, and TLD Parsing for JS
Repository Health
Technical Analysis
tldts is a JavaScript/TypeScript library that extracts hostnames, domains, public suffixes, top-level domains, and subdomains from URLs or raw hostnames. It’s built specifically for performance — the project benchmarks itself against competing libraries like psl, tldjs, parse-domain, and tld-extract, and consistently leads on operations-per-second for getDomain-style parsing on real-world URL corpora.
Unlike naive suffix-splitting approaches, tldts uses a continuously updated copy of the public suffix list compiled into an efficient suffix trie, giving spec-correct results for tricky cases like multi-part suffixes (co.uk), private domains, IDNA/Unicode hostnames, IP address detection, and email address parsing. The monorepo splits functionality across tldts-core (shared parsing logic), tldts-icann/tldts (different public-suffix-list scopes), and tldts-experimental, so consumers can pick a bundle sized to their needs.
What You Get
parse()function returning domain, domainWithoutSuffix, hostname, subdomain, publicSuffix, isIcann, isPrivate, and isIp fields for any URL or hostname- A CLI (
npx tldts <url>) for one-off or batched (stdin) domain parsing without writing any code - IPv4/IPv6 address detection built into the same parsing path as domain extraction
- Full Unicode/IDNA support for internationalized domain names
- Email address parsing support, extracting the domain portion of an email address the same way as a URL
Common Use Cases
- Grouping or deduplicating analytics/log data by registrable domain instead of full hostname (e.g.
mail.google.comandwww.google.comboth resolving togoogle.com) - Validating and normalizing user-submitted URLs or email addresses in a signup or content-moderation pipeline
- Cookie and security tooling that needs correct public-suffix-aware domain boundaries (e.g. determining if a cookie can be set across
co.uksubdomains) - Ad-tech and privacy tools (its author’s browser extension work) that need fast, spec-correct domain classification at scale
Under The Hood
Architecture The monorepo splits concerns cleanly: tldts-core/src/factory.ts builds a configurable parser factory that other packages instantiate with a specific public-suffix dataset, extract-hostname.ts/is-ip.ts/is-valid.ts handle input normalization and validation, and the top-level tldts package’s src/suffix-trie.ts (207 lines) compiles the public suffix list into a trie structure for O(suffix-length) lookups rather than linear list scanning. tldts-icann and tldts-experimental reuse the same tldts-core engine with different suffix datasets (ICANN-only vs. experimental/private suffixes). Tech Stack Pure TypeScript across all six packages, built with Rollup to ESM/CJS/UMD bundles per package, with a bin/ CLI entry point in the tldts package wrapping the same parse() function used programmatically; the project maintains its own benchmark harness (comparison/bench2) comparing throughput against competing libraries on every release. Code Quality tldts-tests is a dedicated package solely for cross-package test fixtures, and packages/tldts/test/ runs dedicated suites (tld.test.ts, publicsuffix.test.ts, special-use.test.ts) covering ICANN rules, private suffixes, and RFC 6761 special-use names (localhost, .test, .invalid, .onion, etc.); the repo’s active commit cadence and consistent dependency updates (via dependabot) reflect ongoing maintenance discipline. API Design The single parse() function with a flat result object (domain, subdomain, publicSuffix, isIcann, isPrivate, isIp) is easy to start with, and the bundled CLI mirrors the same shape for shell use without writing code; choosing between the tldts, tldts-icann, and tldts-experimental variants does require reading the docs to understand suffix-list scope trade-offs, but the default tldts package covers the common case out of the box.
Used by 20 apps in this directory
Plasmic
CMS · Design Tools · Low Code Platforms
The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.
PostHog
Ab Testing Experimentation · Analytics · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
Postiz
Automation · Social Media
The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.
Rocket.Chat
Team Chat
The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.
RSSHub
Automation · Social Media
Turn any website into an RSS feed — social media, streaming platforms, and niche sites all become subscribable in seconds.
Stormkit
Devops · Hosting Control Panel
Self-hostable platform for deploying and hosting modern web apps with automated CI/CD, custom domains, and a built-in serverless runtime — a true open-source alternative to Vercel and Netlify.
Swetrix
Analytics
Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.
Unkey
Developer Tools
An open-source developer platform for API infrastructure — issue and verify API keys, enforce global rate limits, route traffic through a gateway, and get per-key analytics and audit logs.
Unleash
Ab Testing Experimentation · Developer Tools · Devops
The open-source feature management platform that lets you ship code to production and control who sees it — without redeploying.