(values: unknown)
| 10 | * Accepts JSON strings, array-of-arrays, or array-of-objects and normalizes them. |
| 11 | */ |
| 12 | export function normalizeExcelValues(values: unknown): NormalizedExcelValues | undefined { |
| 13 | if (values === null || values === undefined) { |
| 14 | return undefined |
| 15 | } |
| 16 | |
| 17 | if (typeof values === 'string') { |
| 18 | const trimmed = values.trim() |
| 19 | if (!trimmed) { |
| 20 | return undefined |
| 21 | } |
| 22 | |
| 23 | try { |
| 24 | const parsed = JSON.parse(trimmed) |
| 25 | if (!Array.isArray(parsed)) { |
| 26 | throw new Error('Excel values must be an array of rows or array of objects') |
| 27 | } |
| 28 | return parsed as NormalizedExcelValues |
| 29 | } catch (_error) { |
| 30 | throw new Error('Invalid JSON format for values') |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if (Array.isArray(values)) { |
| 35 | return values as NormalizedExcelValues |
| 36 | } |
| 37 | |
| 38 | throw new Error('Excel values must be an array of rows or array of objects') |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Convenience helper for contexts that expect the narrower ToolParams typing. |
no test coverage detected