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