diff --git a/src/index.ts b/src/index.ts index 95cac4e..4a82233 100644 --- a/src/index.ts +++ b/src/index.ts @@ -162,3 +162,23 @@ export const factory = function ( }); }; }; + +export async function maybeGetAsyncProperty(object: any) { + if (typeof object === "function") { + object = object(); + } + + if (isPromise(object)) { + object = await object; + } + + return object; +} + +export function isPromise(obj: Promise) { + return ( + !!obj && + (typeof obj === "object" || typeof obj === "function") && + typeof obj.then === "function" + ); +}