( value: string | object | number | boolean | unknown | undefined, isObjectLike: boolean, )
| 8 | * @returns - JSON stringified value or a plain string |
| 9 | */ |
| 10 | export function getStringifiedValue( |
| 11 | value: string | object | number | boolean | unknown | undefined, |
| 12 | isObjectLike: boolean, |
| 13 | ): string { |
| 14 | if (!value) return ''; |
| 15 | |
| 16 | if (isObjectLike || typeof value === 'object') { |
| 17 | // If the value is a string and is a valid JSON, parse it first to avoid unnecessary double escaped quotation marks |
| 18 | const valueToStringify = typeof value === 'string' && isValidJSON(String(value)) ? parseJSON(String(value)) : value; |
| 19 | return JSON.stringify(valueToStringify, null, 4); |
| 20 | } |
| 21 | |
| 22 | return String(value); |
| 23 | } |
no test coverage detected