resolveObject
Using
Function that retrieves or resolves only object values. This function should handle various input types, resolving functions if encountered, and ultimately return an object if possible.
If the final resolved value is not an object or if a function remains unresolved within the specified depth, the function return undefined
.
Arguments
Argument | Type | Description | Example |
---|---|---|---|
value | object function | Value for resolve. | {} () => () => { name: "Alina" } |
depth | number | Depth of maximum resolve. | 2 |
Returns
object
| undefined
— Returns the resolved object otherwise undefined
.
Examples
resolveObject({ some: true });
// { some: true }
resolveObject(() => () => ({ name: 'Alina' }));
// { name: 'Alina' }
resolveObject(['text', 12]);
// undefined
resolveObject(() => ({ package: shegit }), 1);
// { package: shegit }
resolveObject(() => ({ package: shegit }), 2);
// { package: shegit }
resolveObject(() => ({ package: shegit }), 0);
// undefined