1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
-
- /**
- * @typedef {string} cell
- */
-
- /**
- * @typedef {cell[]} validateData~column
- */
-
- /**
- * @param {column[]} rows
- * @returns {undefined}
- */
- const validateTableData = rows => {
- if (!Array.isArray(rows)) {
- throw new TypeError('Table data must be an array.');
- }
-
- if (rows.length === 0) {
- throw new Error('Table must define at least one row.');
- }
-
- if (rows[0].length === 0) {
- throw new Error('Table must define at least one column.');
- }
-
- const columnNumber = rows[0].length;
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
-
- try {
- for (var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- const cells = _step.value;
-
- if (!Array.isArray(cells)) {
- throw new TypeError('Table row data must be an array.');
- }
-
- if (cells.length !== columnNumber) {
- throw new Error('Table must have a consistent number of cells.');
- } // @todo Make an exception for newline characters.
- // @see https://github.com/gajus/table/issues/9
-
-
- var _iteratorNormalCompletion2 = true;
- var _didIteratorError2 = false;
- var _iteratorError2 = undefined;
-
- try {
- for (var _iterator2 = cells[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
- const cell = _step2.value;
-
- // eslint-disable-next-line no-control-regex
- if (/[\u0001-\u001A]/.test(cell)) {
- throw new Error('Table data must not contain control characters.');
- }
- }
- } catch (err) {
- _didIteratorError2 = true;
- _iteratorError2 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
- _iterator2.return();
- }
- } finally {
- if (_didIteratorError2) {
- throw _iteratorError2;
- }
- }
- }
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- };
-
- var _default = validateTableData;
- exports.default = _default;
- //# sourceMappingURL=validateTableData.js.map
|