• Function to safely execute a callback function, if the function throws the provided default value will be returned.

    Type Parameters

    • T = boolean

    Parameters

    • cb: (() => T)

      Callback function be wrapped with an exception

        • (): T
        • Returns T

    • defValue: T

      The default value to return when an exception is thrown

    Returns T

    The result of the callback function or the default if an exception occurred calling the callback function.

    0.9.5

    let theExpression = "{ invalid: json value";

    let result = safeGet(() => {
    return JSON.parse(theExpression);
    }, {});

    // result === {};