blob: 60ae3074093ddb3b393b13b61886d57b19d7c225 [file] [log] [blame]
Yang Guo4fd355c2019-09-19 10:59:03 +02001"use strict";
Tim van der Lippe38208902021-05-11 16:37:59 +01002Object.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.');
Yang Guo4fd355c2019-09-19 10:59:03 +02008 }
Tim van der Lippe38208902021-05-11 16:37:59 +01009 if (rows.length === 0) {
10 throw new Error('Table must define at least one row.');
Tim van der Lippeb97da6b2021-02-12 14:32:53 +000011 }
Tim van der Lippe38208902021-05-11 16:37:59 +010012 if (rows[0].length === 0) {
13 throw new Error('Table must define at least one column.');
Yang Guo4fd355c2019-09-19 10:59:03 +020014 }
Tim van der Lippe38208902021-05-11 16:37:59 +010015 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(utils_1.normalizeString(String(cell)))) {
26 throw new Error('Table data must not contain control characters.');
27 }
28 }
29 }
Yang Guo4fd355c2019-09-19 10:59:03 +020030};
Tim van der Lippe38208902021-05-11 16:37:59 +010031exports.validateTableData = validateTableData;