Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e4559d805 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.24.0",
|
||||
"version": "0.24.1",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
11
src/misc.ts
11
src/misc.ts
@ -1,6 +1,17 @@
|
||||
import {PathEvent} from './path-events.ts';
|
||||
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
|
||||
*
|
||||
|
Reference in New Issue
Block a user