(input: unknown[][])
| 110 | */ |
| 111 | // eslint-disable-next-line no-restricted-globals |
| 112 | export function _dataToHTML(input: unknown[][]): string { |
| 113 | const inputLen = input.length; |
| 114 | const result = ['<table>']; |
| 115 | |
| 116 | for (let row = 0; row < inputLen; row += 1) { |
| 117 | const rowData = input[row]; |
| 118 | const columnsLen = rowData.length; |
| 119 | const columnsResult = []; |
| 120 | |
| 121 | if (row === 0) { |
| 122 | result.push('<tbody>'); |
| 123 | } |
| 124 | |
| 125 | for (let column = 0; column < columnsLen; column += 1) { |
| 126 | const cellData = rowData[column]; |
| 127 | const parsedCellData = isEmpty(cellData) ? |
| 128 | '' : |
| 129 | (cellData as { toString(): string }).toString() |
| 130 | .replaceAll('&', '&') |
| 131 | .replaceAll('<', '<') |
| 132 | .replaceAll('>', '>') |
| 133 | .replace(/(<br(\s*|\/)>(\r\n|\n)?|\r\n|\n)/g, '<br>\r\n') |
| 134 | .replace(/\x20{2,}/gi, (substring: string) => { |
| 135 | // The way how Excel serializes data with at least two spaces. |
| 136 | return `<span style="mso-spacerun: yes">${' '.repeat(substring.length - 1)} </span>`; |
| 137 | }) |
| 138 | .replace(/\t/gi, '	'); |
| 139 | |
| 140 | columnsResult.push(`<td>${parsedCellData}</td>`); |
| 141 | } |
| 142 | |
| 143 | result.push('<tr>', ...columnsResult, '</tr>'); |
| 144 | |
| 145 | if (row + 1 === inputLen) { |
| 146 | result.push('</tbody>'); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | result.push('</table>'); |
| 151 | |
| 152 | return result.join(''); |
| 153 | } |
| 154 | |
| 155 | const TD_OPEN = /<td\b[^>]*>/i; |
| 156 | const TD_CLOSE = /<\/\s*td\s*>/i; |
no test coverage detected
searching dependent graphs…