Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 1 | "use strict"; |
| 2 | |
| 3 | Object.defineProperty(exports, "__esModule", { |
| 4 | value: true |
| 5 | }); |
| 6 | exports.default = void 0; |
| 7 | |
| 8 | /** |
| 9 | * @typedef {string} cell |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @typedef {cell[]} validateData~column |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * @param {column[]} rows |
| 18 | * @returns {undefined} |
| 19 | */ |
| 20 | const validateTableData = rows => { |
| 21 | if (!Array.isArray(rows)) { |
| 22 | throw new TypeError('Table data must be an array.'); |
| 23 | } |
| 24 | |
| 25 | if (rows.length === 0) { |
| 26 | throw new Error('Table must define at least one row.'); |
| 27 | } |
| 28 | |
| 29 | if (rows[0].length === 0) { |
| 30 | throw new Error('Table must define at least one column.'); |
| 31 | } |
| 32 | |
| 33 | const columnNumber = rows[0].length; |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 34 | |
Tim van der Lippe | b97da6b | 2021-02-12 14:32:53 +0000 | [diff] [blame^] | 35 | for (const cells of rows) { |
| 36 | if (!Array.isArray(cells)) { |
| 37 | throw new TypeError('Table row data must be an array.'); |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 38 | } |
Tim van der Lippe | b97da6b | 2021-02-12 14:32:53 +0000 | [diff] [blame^] | 39 | |
| 40 | if (cells.length !== columnNumber) { |
| 41 | throw new Error('Table must have a consistent number of cells.'); |
| 42 | } |
| 43 | |
| 44 | for (const cell of cells) { |
| 45 | // eslint-disable-next-line no-control-regex |
| 46 | if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) { |
| 47 | throw new Error('Table data must not contain control characters.'); |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | var _default = validateTableData; |
| 54 | exports.default = _default; |
| 55 | //# sourceMappingURL=validateTableData.js.map |