Added async function runner
This commit is contained in:
parent
95f8d5762c
commit
2e4559d805
@ -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",
|
||||||
|
11
src/misc.ts
11
src/misc.ts
@ -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
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user