diff --git a/src/util.ts b/src/util.ts index e9e55d9..952b658 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,3 +1,5 @@ +import { DNSRecord, DNSResult } from "./types.js"; + export function getTld(domain: string): string { if (domain.includes(".")) { domain = domain.split(".")[domain.split(".").length - 1]; @@ -28,3 +30,24 @@ export function isDomain(domain: string) { domain ); } +export function resolverEmptyResponse(): DNSResult { + return { + records: [], + }; +} + +export function resolverError(e: Error | string): DNSResult { + if (!(e instanceof Error)) { + e = new Error(e); + } + return { + records: [], + error: e, + }; +} + +export function resolveSuccess(records: DNSRecord[]): DNSResult { + return { + records, + }; +}