( table: TableRow[] | Record<string, any> | string | null )
| 4 | * Transforms a table from the store format to a key-value object. |
| 5 | */ |
| 6 | export const transformTable = ( |
| 7 | table: TableRow[] | Record<string, any> | string | null |
| 8 | ): Record<string, any> => { |
| 9 | if (!table) return {} |
| 10 | |
| 11 | if (typeof table === 'string') { |
| 12 | try { |
| 13 | const parsed = JSON.parse(table) as TableRow[] | Record<string, any> |
| 14 | return transformTable(parsed) |
| 15 | } catch { |
| 16 | return {} |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | if (Array.isArray(table)) { |
| 21 | return table.reduce( |
| 22 | (acc, row) => { |
| 23 | if (row.cells?.Key && row.cells?.Value !== undefined) { |
| 24 | const value = row.cells.Value |
| 25 | acc[row.cells.Key] = value |
| 26 | } |
| 27 | return acc |
| 28 | }, |
| 29 | {} as Record<string, any> |
| 30 | ) |
| 31 | } |
| 32 | |
| 33 | if (typeof table === 'object') { |
| 34 | return table |
| 35 | } |
| 36 | |
| 37 | return {} |
| 38 | } |
no test coverage detected