UNPKG

1.22 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.validateTableData = void 0;
4const utils_1 = require("./utils");
5const 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};
31exports.validateTableData = validateTableData;
32//# sourceMappingURL=validateTableData.js.map
\No newline at end of file