(data: any[], code: string)
| 77 | * The code must assign its final output to a variable named `result`. |
| 78 | */ |
| 79 | export async function executeCode(data: any[], code: string): Promise<any> { |
| 80 | try { |
| 81 | if (typeof document === 'undefined') { |
| 82 | return await executeInNode(data, code); |
| 83 | } |
| 84 | |
| 85 | return await executeInBrowser(data, code); |
| 86 | } catch (error) { |
| 87 | const rawMessage = error instanceof Error ? error.message : String(error); |
| 88 | const message = rawMessage.startsWith('Failed to execute data code:') |
| 89 | ? rawMessage |
| 90 | : `Failed to execute data code: ${rawMessage.replace(/^Error:\s*/, '')}`; |
| 91 | throw new Error(message); |
| 92 | } |
| 93 | } |
no test coverage detected