@newdash/newdash
Version:
javascript/typescript utility library
67 lines (66 loc) • 1.4 kB
TypeScript
/**
* @internal
* @ignore
* @private
*/
type Func = (...args: any[]) => any;
/**
* @internal
* @ignore
* @private
*/
interface WrapperContext<T extends Func, G = any> {
global: G;
args: Parameters<T>;
runner: T;
state: any;
thisContext?: any;
}
/**
* @internal
* @ignore
* @private
*/
interface WrapperOptions<T extends Func, G = any> {
/**
* global state of the function instance
*/
global?: G;
/**
* before runner call, return a value to skip execute runner
*/
before?: (ctx: WrapperContext<T, G>) => any;
/**
* overwrite function execution
*
* @since 5.19.0
*/
execute?: (ctx: WrapperContext<T, G>) => ReturnType<T>;
/**
* after runner call, change result
*/
after?: (ctx: WrapperContext<T, G>, result: ReturnType<T>) => any;
/**
* error raised, return the customized value or raise error
*/
error?: (ctx: WrapperContext<T, G>, error: Error) => any;
/**
* force binding 'this' context to target
* @since 5.19.0
*/
thisContext?: any;
}
/**
*
* create function wrapper for sync/async function
*
* @category Functional
* @since 5.18.0
* @param runner
* @param options
*
*/
export declare function createFunctionWrapper<T extends Func, G extends any>(runner: T, options: WrapperOptions<T, G>): T & {
__wrap_global__: G;
};
export {};