(output: any)
| 1554 | * @returns {any} - The parsed output or original output if not parseable |
| 1555 | */ |
| 1556 | const parseOutput = (output: any): any => { |
| 1557 | // If output is not a string, return as-is |
| 1558 | if (typeof output !== 'string') { |
| 1559 | return output |
| 1560 | } |
| 1561 | |
| 1562 | // Trim whitespace |
| 1563 | const trimmedOutput = output.trim() |
| 1564 | |
| 1565 | // Check if it's an empty string |
| 1566 | if (!trimmedOutput) { |
| 1567 | return output |
| 1568 | } |
| 1569 | |
| 1570 | // Check if it looks like JSON (starts with { or [) |
| 1571 | if ((trimmedOutput.startsWith('{') && trimmedOutput.endsWith('}')) || (trimmedOutput.startsWith('[') && trimmedOutput.endsWith(']'))) { |
| 1572 | try { |
| 1573 | const parsedOutput = parseJsonBody(trimmedOutput) |
| 1574 | return parsedOutput |
| 1575 | } catch (e) { |
| 1576 | return output |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | // Return the original string if it doesn't look like JSON |
| 1581 | return output |
| 1582 | } |
| 1583 | |
| 1584 | /** |
| 1585 | * Execute JavaScript code using either Sandbox or NodeVM |
no test coverage detected