Files
cool-domain-web/src/lib/whois.ts
T
klemek 98f937e9de
Deploy / Build (push) Successful in 9m32s
Lint / ESLint (push) Successful in 6m40s
Lint / Oxlint (push) Successful in 5m0s
Lint / TypeScript (push) Successful in 5m24s
Deploy / Deploy to Stapler (push) Successful in 5m52s
fix: check more whois data
2026-06-16 11:42:00 +02:00

40 lines
938 B
TypeScript

import type {
WhoIsResponse,
WhoIsData,
WhoIsEvent,
WhoIsIpAddresses,
} from "@/types";
function checkEvents(events: WhoIsEvent[]): boolean {
for (const event of events) {
if (event.eventAction === "registration" && event.eventDate === "") {
return true;
}
}
return false;
}
function checkIpAddresses(ipAddresses: WhoIsIpAddresses): boolean {
return ipAddresses.v4.length === 0 && ipAddresses.v6.length === 0;
}
function checkWhoIsData(data: WhoIsData): boolean {
return (
checkEvents(data.events) &&
checkIpAddresses(data.ipAddresses) &&
data.nameservers.length === 0
);
}
export async function isDomainAvailable(domain: string): Promise<boolean> {
try {
const response = await fetch(
`https://whois.klemek.fr/api/lookup/${domain}`,
);
const content: WhoIsResponse = await response.json();
return checkWhoIsData(content.data);
} catch {
return false;
}
}