Wraps a function with a wrapper function, allowing pre- or post-processing.
The original function to wrap.
A function that receives the original function and arguments, can modify behavior or result.
A new function wrapped with the provided wrapper.
const logWrapper = wrap( (x: number) => x * 2, (fn, x) => { console.log("Input:", x); const result = fn(x); console.log("Output:", result); return result; });logWrapper(5);// Logs: "Input: 5" then "Output: 10" Copy
const logWrapper = wrap( (x: number) => x * 2, (fn, x) => { console.log("Input:", x); const result = fn(x); console.log("Output:", result); return result; });logWrapper(5);// Logs: "Input: 5" then "Output: 10"
1.1.0
Wraps a function with a wrapper function, allowing pre- or post-processing.