• Given a deep-search query path, returns an object property or array value of an object or array as an AnyFunction, or undefined if a value was not found or was not type-compatible.

    const obj = { foo: { bar: [(arg: string) => `Hi, ${arg}`] } };
    const value = getFunction(obj, 'foo.bar[0]');
    // type of value -> AnyArray; value -> (arg: string) => `Hi, ${arg}`

    Parameters

    • from: unknown

      Any value to query.

    • path: string

      The query path.

    Returns Nullable<AnyFunction>

  • Given a deep-search query path, returns an object property or array value of an object or array as an AnyFunction, or undefined if a value was not found or was not type-compatible.

    const obj = { foo: { bar: [(arg: string) => `Hi, ${arg}`] } };
    const value = getFunction(obj, 'foo.bar[1]', (arg: string) => `Bye, ${arg}`);
    // type of value -> AnyArray; value -> (arg: string) => `Bye, ${arg}`)

    Parameters

    • from: unknown

      Any value to query.

    • path: string

      The query path.

    • defaultValue: AnyFunction

      The default to return if the query result was not defined.

    Returns AnyFunction