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