source: node_modules/es-toolkit/dist/compat/function/wrap.d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * Creates a new function that wraps the given function `func`.
3 * In this process, you can apply additional logic defined in the `wrapper` function before and after the execution of the original function.
4 *
5 * If a `value` is provided instead of a function, this value is passed as the first argument to the `wrapper` function.
6 *
7 * @template T - The type of the value being wrapped.
8 * @template U - The type of the arguments being passed to the `wrapper` function.
9 * @template V - The type of the return value of the `wrapper` function.
10 * @param {T} value - The value to be wrapped.
11 * @param {(value: T, ...args: U[]) => V} wrapper - The function to wrap the value with.
12 * @returns {(...args: U[]) => V} A new function that wraps the value with the `wrapper` function.
13 *
14 * @example
15 * // Wrap a function
16 * const greet = (name: string) => `Hi, ${name}`;
17 * const wrapped = wrap(greet, (value, name) => `[LOG] ${value(name)}`);
18 * wrapped('Bob'); // => "[LOG] Hi, Bob"
19 *
20 * @example
21 * // Wrap a primitive value
22 * const wrapped = wrap('value', v => `<p>${v}</p>`);
23 * wrapped(); // => "<p>value</p>"
24 */
25declare function wrap<T, U, V>(value: T, wrapper: (value: T, ...args: U[]) => V): (...args: U[]) => V;
26
27export { wrap };
Note: See TracBrowser for help on using the repository browser.