Parse domain names and get TLD characteristics like WHOIS privacy support and registration restrictions
npm install whoistldA TypeScript package using Zod for parsing domain names and extracting TLD (Top-Level Domain) characteristics including WHOIS privacy support, registration restrictions, and other properties.
- 🚀 Zero Dependencies (except Zod) - All data is embedded in the package
- 🔒 Type-Safe - Full TypeScript support with Zod schemas
- 🌐 Comprehensive TLD Data - Information about gTLDs, ccTLDs, and sponsored TLDs
- ⚡ Fast - No remote requests, all data is local
- 📦 Lightweight - Minimal package size
``bash`
npm install whoistld
`typescript
import { parseDomain } from 'whoistld';
// Parse a full domain
const result = parseDomain('example.com');
console.log(result);
// {
// input: 'example.com',
// tld: 'com',
// domain: 'example',
// characteristics: {
// tld: 'com',
// whoisPrivacySupport: true,
// registrationRestrictions: 'none',
// dnssecSupport: true,
// idn: true,
// category: 'generic',
// description: 'Commercial - most popular gTLD'
// }
// }
// Parse a subdomain
const subdomainResult = parseDomain('blog.example.com');
console.log(subdomainResult);
// {
// input: 'blog.example.com',
// tld: 'com',
// domain: 'example',
// subdomain: 'blog',
// characteristics: { ... }
// }
// Parse just a TLD
const tldResult = parseDomain('.edu');
console.log(tldResult);
// {
// input: '.edu',
// tld: 'edu',
// characteristics: {
// tld: 'edu',
// whoisPrivacySupport: false,
// registrationRestrictions: 'educational',
// dnssecSupport: true,
// idn: false,
// category: 'sponsored',
// description: 'Educational institutions - restricted to accredited institutions'
// }
// }
`
`typescript
import { supportsWhoisPrivacy } from 'whoistld';
console.log(supportsWhoisPrivacy('com')); // true
console.log(supportsWhoisPrivacy('edu')); // false
console.log(supportsWhoisPrivacy('xyz')); // true
console.log(supportsWhoisPrivacy('unknown')); // null
`
`typescript
import { getTldData } from 'whoistld';
const comData = getTldData('com');
console.log(comData);
// {
// tld: 'com',
// whoisPrivacySupport: true,
// registrationRestrictions: 'none',
// dnssecSupport: true,
// idn: true,
// category: 'generic',
// description: 'Commercial - most popular gTLD'
// }
const govData = getTldData('gov');
console.log(govData);
// {
// tld: 'gov',
// whoisPrivacySupport: false,
// registrationRestrictions: 'governmental',
// dnssecSupport: true,
// idn: false,
// category: 'sponsored',
// description: 'US Government - restricted to US government entities'
// }
`
`typescript
import { getAllTlds, isKnownTld } from 'whoistld';
const allTlds = getAllTlds();
console.log(allTlds);
// ['com', 'net', 'org', 'edu', 'gov', 'mil', ...]
console.log(isKnownTld('com')); // true
console.log(isKnownTld('xyz')); // true
console.log(isKnownTld('invalid')); // false
`
`typescript
import { parseDomain, ParsedDomainSchema } from 'whoistld';
// The result is already validated with Zod
const result = parseDomain('example.com');
// You can also use the schema directly
try {
const validated = ParsedDomainSchema.parse(result);
console.log(validated);
} catch (error) {
console.error('Validation error:', error);
}
`
By default, this package collects anonymous analytics when an unknown TLD is encountered. This helps us identify missing TLDs and improve the package's coverage. No personal data is collected - only the unknown TLD string is sent.
If you prefer to disable this analytics collection, you can do so using the configure function:
`typescript
import { configure } from 'whoistld';
// Disable analytics collection
configure({ disableAnalytics: true });
`
You can also check the current configuration:
`typescript
import { getConfig } from 'whoistld';
const config = getConfig();
console.log(config.disableAnalytics); // false (default) or true if disabled
`
Parses a domain name and returns comprehensive information including TLD characteristics.
Parameters:
- input - Domain name (can be full domain, partial, or just TLD)
Returns: ParsedDomain object containing:input
- - Original input stringtld
- - Extracted TLDdomain
- - Domain name (if present)subdomain
- - Subdomain (if present)characteristics
- - TLD characteristics (or null if TLD is unknown)
Checks if a TLD supports WHOIS privacy.
Returns:
- true if supportedfalse
- if not supportednull
- if TLD is unknown
Gets TLD characteristics for a specific TLD.
Returns: TLD characteristics object or null if unknown
Returns an array of all known TLD strings in the database.
Checks if a TLD exists in the database.
Configure the whoistld module.
Parameters:
- options - Configuration object with the following properties:disableAnalytics
- (optional, boolean) - When true, disables analytics collection for missing TLDs. Default: false
Returns the current configuration object.
Each TLD has the following characteristics:
- tld - The TLD string
- whoisPrivacySupport - Whether the TLD supports WHOIS privacy/proxy services
- registrationRestrictions - Type of registration restrictions:
- none - Open to anyonegovernmental
- - Restricted to government entitieseducational
- - Restricted to educational institutionsorganizational
- - Restricted to specific types of organizationsgeographic
- - Geographic restrictionsreserved
- - Reserved/special usegeneric
- dnssecSupport - Whether DNSSEC is supported
- idn - Whether Internationalized Domain Names are supported
- category - TLD category:
- - Generic TLDcountry-code
- - Country code TLDsponsored
- - Sponsored TLD with restrictionsinfrastructure
- - Infrastructure TLDtest
- - Test/example TLDgeneric-restricted
- - Generic restricted TLD
- description - Human-readable description (optional)
The package includes data for many popular TLDs including:
- Generic TLDs: com, net, org, info, biz, dev, app, tech, online, store, blog, xyz
- Country Code TLDs: us, uk, de, fr, jp, cn, au, ca, io
- Sponsored/Restricted TLDs: edu, gov, mil, int, museum, coop, aero
- Infrastructure/Test TLDs: arpa, test, localhost, example
All types are exported for use in your TypeScript projects:
`typescript``
import type {
ParsedDomain,
TldCharacteristics,
RegistrationRestriction,
TldCategory,
WhoistldConfig,
} from 'whoistld';
- Fast: All data is embedded, no API calls or remote requests
- Reliable: No network dependencies means consistent performance
- Type-Safe: Full TypeScript and Zod schema support
- Privacy-Aware: Helps determine if WHOIS privacy is available for a domain
- Comprehensive: Includes data about various TLD characteristics
ISC
Contributions are welcome! Please feel free to submit a Pull Request.