From 692417b1e584a8fc9221b2decf1d0b1908be2229 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 18 Aug 2022 14:03:04 -0400 Subject: [PATCH] *Add helper functions for handling resolver responses --- src/util.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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, + }; +}