.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / table / dist / validateTableData.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4   value: true
5 });
6
7 /**
8  * @typedef {string} cell
9  */
10
11 /**
12  * @typedef {cell[]} validateData~column
13  */
14
15 /**
16  * @param {column[]} rows
17  * @returns {undefined}
18  */
19 exports.default = rows => {
20   if (!Array.isArray(rows)) {
21     throw new TypeError('Table data must be an array.');
22   }
23
24   if (rows.length === 0) {
25     throw new Error('Table must define at least one row.');
26   }
27
28   if (rows[0].length === 0) {
29     throw new Error('Table must define at least one column.');
30   }
31
32   const columnNumber = rows[0].length;
33
34   for (const cells of rows) {
35     if (!Array.isArray(cells)) {
36       throw new TypeError('Table row data must be an array.');
37     }
38
39     if (cells.length !== columnNumber) {
40       throw new Error('Table must have a consistent number of cells.');
41     }
42
43     // @todo Make an exception for newline characters.
44     // @see https://github.com/gajus/table/issues/9
45     for (const cell of cells) {
46       if (/[\u0001-\u001A]/.test(cell)) {
47         throw new Error('Table data must not contain control characters.');
48       }
49     }
50   }
51 };