*Add helper functions for handling resolver responses
This commit is contained in:
parent
6e961044e5
commit
692417b1e5
23
src/util.ts
23
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,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue