From 1e62962a1d90d850149279a9ab40b4c7de4fecfa Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 19 Feb 2023 18:03:32 -0500 Subject: [PATCH] *Refactor isTldSupported to support promises --- src/resolverModule.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/resolverModule.ts b/src/resolverModule.ts index 9690f34..226f905 100644 --- a/src/resolverModule.ts +++ b/src/resolverModule.ts @@ -1,5 +1,5 @@ import type { DNSResult, ResolverOptions } from "./types.js"; -import { getTld } from "./util.js"; +import { getTld, isPromise } from "./util.js"; declare class ResolverRegistry { get resolvers(): Set | Promise>; @@ -23,7 +23,7 @@ export interface ResolverModule extends ResolverModuleConstructor { bypassCache: boolean ): Promise; - getSupportedTlds(): string[]; + getSupportedTlds(): string[] | Promise; } // ts-ignore @@ -40,11 +40,18 @@ export abstract class AbstractResolverModule { bypassCache: boolean ): Promise; - getSupportedTlds(): string[] { + getSupportedTlds(): string[] | Promise { return []; } - isTldSupported(domain: string): boolean { - return this.getSupportedTlds().includes(getTld(domain)); + isTldSupported(domain: string): boolean | Promise { + let supported = this.getSupportedTlds(); + if (isPromise(supported as Promise)) { + return (supported as Promise).then((supported: string[]) => { + return supported.includes(getTld(domain)); + }); + } + + return (supported as string[]).includes(getTld(domain)); } }