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.

95 lines
2.4 KiB

4 years ago
  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. }
  39. var _iteratorNormalCompletion2 = true;
  40. var _didIteratorError2 = false;
  41. var _iteratorError2 = undefined;
  42. try {
  43. for (var _iterator2 = cells[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  44. const cell = _step2.value;
  45. // eslint-disable-next-line no-control-regex
  46. if (/[\u0001-\u0006\u0008-\u0009\u000B-\u001A]/.test(cell)) {
  47. throw new Error('Table data must not contain control characters.');
  48. }
  49. }
  50. } catch (err) {
  51. _didIteratorError2 = true;
  52. _iteratorError2 = err;
  53. } finally {
  54. try {
  55. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  56. _iterator2.return();
  57. }
  58. } finally {
  59. if (_didIteratorError2) {
  60. throw _iteratorError2;
  61. }
  62. }
  63. }
  64. }
  65. } catch (err) {
  66. _didIteratorError = true;
  67. _iteratorError = err;
  68. } finally {
  69. try {
  70. if (!_iteratorNormalCompletion && _iterator.return != null) {
  71. _iterator.return();
  72. }
  73. } finally {
  74. if (_didIteratorError) {
  75. throw _iteratorError;
  76. }
  77. }
  78. }
  79. };
  80. var _default = validateTableData;
  81. exports.default = _default;
  82. //# sourceMappingURL=validateTableData.js.map