Function logGuard

  • 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'
    const test = {} as string | null;
    if (logGuard(isNull)(test)) {
    test; // null
    }
    // hooking to log
    const hookLog = hookGuard(
    isNull,
    ({value, guard}) => console.info(`Calling:`, { guard, value }),
    ({result}) => console.info(`Result:`, { result })
    );

    Type Parameters

    Parameters

    • guard: Guard
    • Optional before: ((__namedParameters: {
          guard: Guard;
          value: unknown;
      }) => void)
        • (__namedParameters: {
              guard: Guard;
              value: unknown;
          }): void
        • Parameters

          • __namedParameters: {
                guard: Guard;
                value: unknown;
            }
            • Readonly guard: Guard
            • Readonly value: unknown

          Returns void

    • Optional after: ((__namedParameters: {
          guard: Guard;
          result: boolean;
          value: unknown;
      }) => void)
        • (__namedParameters: {
              guard: Guard;
              result: boolean;
              value: unknown;
          }): void
        • Parameters

          • __namedParameters: {
                guard: Guard;
                result: boolean;
                value: unknown;
            }
            • Readonly guard: Guard
            • Readonly result: boolean
            • Readonly value: unknown

          Returns void

    Returns Guard

Generated using TypeDoc