*Add helper functions for handling resolver responses

This commit is contained in:
Derrick Hammer 2022-08-18 14:03:04 -04:00
parent 6e961044e5
commit 692417b1e5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 23 additions and 0 deletions

View File

@ -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,
};
}