Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
3fd5c5ed57 | |||
2e4559d805 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.24.0",
|
||||
"version": "0.24.2",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
12
src/misc.ts
12
src/misc.ts
@ -1,6 +1,18 @@
|
||||
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
|
||||
* @param {boolean} async Run with async (returns a promise)
|
||||
* @return {T | Promise<T>} Function return result
|
||||
*/
|
||||
export function fn<T>(args: object, fn: string, async: boolean = false): T {
|
||||
const keys = Object.keys(args);
|
||||
return new Function(...keys, `return (${async ? 'async ' : ''}(${keys.join(',')}) => { ${fn} })(${keys.join(',')})`)(...keys.map(k => (<any>args)[k]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profile image from Gravatar
|
||||
*
|
||||
|
Reference in New Issue
Block a user