Public
Back
Version 3
2/23/2024
export async function module<ModuleType>(moduleName: string) {
const url = moduleName[0] === "@"
? `https://esm.town/v/${moduleName.slice(1)}`
: moduleName;
return import(url) as Promise<ModuleType>;
}
export function val<ModuleType>(name: string) {
return module<ModuleType>(`@${name}`);
}
export async function call<ModuleType, TMethod extends keyof ModuleType>(
moduleName: string,
methodName: TMethod,
args: any[],
) {
const _module = await module<ModuleType>(moduleName);
const method = _module[methodName];
return method(...args) as ReturnType<ModuleType[TMethod]>;
}
Updated: March 2, 2024