Added async function runner
All checks were successful
Build / Build NPM Project (push) Successful in 37s
Build / Tag Version (push) Successful in 8s
Build / Publish Documentation (push) Successful in 34s

This commit is contained in:
Zakary Timson 2025-05-06 16:09:24 -04:00
parent 95f8d5762c
commit 2e4559d805
2 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.24.0", "version": "0.24.1",
"description": "Utility library", "description": "Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@ -1,6 +1,17 @@
import {PathEvent} from './path-events.ts'; import {PathEvent} from './path-events.ts';
import {md5} from './string'; import {md5} from './string';
/**
* Run a stringified function with arguments asynchronously
* @param {object} args Map of key/value arguments
* @param {string} fn Function as string
* @return {Promise<T>} Function string response
*/
export function asyncFunction<T>(args: object, fn: string): Promise<T> {
const keys = Object.keys(args);
return new Function(...keys, `return (async (${keys.join(',')}) => { ${fn} })(${keys.join(',')})`)(...keys.map(k => (<any>args)[k]));
}
/** /**
* Get profile image from Gravatar * Get profile image from Gravatar
* *