Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validateTableData.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. /**
  7. * @typedef {string} cell
  8. */
  9. /**
  10. * @typedef {cell[]} validateData~column
  11. */
  12. /**
  13. * @param {column[]} rows
  14. * @returns {undefined}
  15. */
  16. const validateTableData = rows => {
  17. if (!Array.isArray(rows)) {
  18. throw new TypeError('Table data must be an array.');
  19. }
  20. if (rows.length === 0) {
  21. throw new Error('Table must define at least one row.');
  22. }
  23. if (rows[0].length === 0) {
  24. throw new Error('Table must define at least one column.');
  25. }
  26. const columnNumber = rows[0].length;
  27. var _iteratorNormalCompletion = true;
  28. var _didIteratorError = false;
  29. var _iteratorError = undefined;
  30. try {
  31. for (var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  32. const cells = _step.value;
  33. if (!Array.isArray(cells)) {
  34. throw new TypeError('Table row data must be an array.');
  35. }
  36. if (cells.length !== columnNumber) {
  37. throw new Error('Table must have a consistent number of cells.');
  38. } // @todo Make an exception for newline characters.
  39. // @see https://github.com/gajus/table/issues/9
  40. var _iteratorNormalCompletion2 = true;
  41. var _didIteratorError2 = false;
  42. var _iteratorError2 = undefined;
  43. try {
  44. for (var _iterator2 = cells[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  45. const cell = _step2.value;
  46. // eslint-disable-next-line no-control-regex
  47. if (/[\u0001-\u001A]/.test(cell)) {
  48. throw new Error('Table data must not contain control characters.');
  49. }
  50. }
  51. } catch (err) {
  52. _didIteratorError2 = true;
  53. _iteratorError2 = err;
  54. } finally {
  55. try {
  56. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  57. _iterator2.return();
  58. }
  59. } finally {
  60. if (_didIteratorError2) {
  61. throw _iteratorError2;
  62. }
  63. }
  64. }
  65. }
  66. } catch (err) {
  67. _didIteratorError = true;
  68. _iteratorError = err;
  69. } finally {
  70. try {
  71. if (!_iteratorNormalCompletion && _iterator.return != null) {
  72. _iterator.return();
  73. }
  74. } finally {
  75. if (_didIteratorError) {
  76. throw _iteratorError;
  77. }
  78. }
  79. }
  80. };
  81. var _default = validateTableData;
  82. exports.default = _default;
  83. //# sourceMappingURL=validateTableData.js.map