Given a Type Guard, returns a Type Guard that does exactly the same but logs the guard, value before calling guard(value). Logs result after.
Equivalent of hookGuard, but uses console.log for the before and after hook by default.
Example
import { logGuard, isNull } from'type-guard-helpers' consttest = {} asstring | null; if (logGuard(isNull)(test)) { test; // null } // hooking to log consthookLog = hookGuard( isNull, ({value, guard}) =>console.info(`Calling:`, { guard, value }), ({result}) =>console.info(`Result:`, { result }) );
Given a Type Guard, returns a Type Guard that does exactly the same but logs the
guard,valuebefore calling guard(value). Logs result after. Equivalent ofhookGuard, but usesconsole.logfor the before and after hook by default.Example