validateTableData.js
1 "use strict"; 2 Object.defineProperty(exports, "__esModule", { value: true }); 3 exports.validateTableData = void 0; 4 const utils_1 = require("./utils"); 5 const validateTableData = (rows) => { 6 if (!Array.isArray(rows)) { 7 throw new TypeError('Table data must be an array.'); 8 } 9 if (rows.length === 0) { 10 throw new Error('Table must define at least one row.'); 11 } 12 if (rows[0].length === 0) { 13 throw new Error('Table must define at least one column.'); 14 } 15 const columnNumber = rows[0].length; 16 for (const row of rows) { 17 if (!Array.isArray(row)) { 18 throw new TypeError('Table row data must be an array.'); 19 } 20 if (row.length !== columnNumber) { 21 throw new Error('Table must have a consistent number of cells.'); 22 } 23 for (const cell of row) { 24 // eslint-disable-next-line no-control-regex 25 if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test((0, utils_1.normalizeString)(String(cell)))) { 26 throw new Error('Table data must not contain control characters.'); 27 } 28 } 29 } 30 }; 31 exports.validateTableData = validateTableData; 32 //# sourceMappingURL=validateTableData.js.map