table 6.0.8 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +53 -1
  2. package/dist/src/alignString.js +64 -0
  3. package/dist/src/alignTableData.js +21 -0
  4. package/dist/src/calculateCellHeight.js +17 -0
  5. package/dist/src/calculateCellWidthIndex.js +17 -0
  6. package/dist/src/calculateMaximumColumnWidthIndex.js +25 -0
  7. package/dist/src/calculateRowHeightIndex.js +30 -0
  8. package/dist/src/createStream.js +74 -0
  9. package/dist/src/drawBorder.js +55 -0
  10. package/dist/src/drawHorizontalContent.js +19 -0
  11. package/dist/src/drawRow.js +17 -0
  12. package/dist/src/drawTable.js +38 -0
  13. package/dist/src/getBorderCharacters.js +83 -0
  14. package/dist/{index.js.flow → src/index.d.ts} +2 -6
  15. package/dist/src/index.js +24 -0
  16. package/dist/src/makeConfig.js +59 -0
  17. package/dist/src/makeStreamConfig.js +60 -0
  18. package/dist/src/mapDataUsingRowHeightIndex.js +27 -0
  19. package/dist/src/padTableData.js +11 -0
  20. package/dist/src/stringifyTableData.js +8 -0
  21. package/dist/src/table.js +28 -0
  22. package/dist/src/truncateTableData.js +20 -0
  23. package/dist/src/types/api.d.ts +99 -0
  24. package/dist/src/types/api.js +3 -0
  25. package/dist/src/types/internal.js +3 -0
  26. package/dist/src/validateConfig.js +27 -0
  27. package/dist/src/validateTableData.js +29 -0
  28. package/dist/{validators.js → src/validators.js} +54 -14
  29. package/dist/src/wrapCell.js +33 -0
  30. package/dist/src/wrapString.js +25 -0
  31. package/dist/src/wrapWord.js +29 -0
  32. package/package.json +33 -26
  33. package/dist/alignString.js +0 -108
  34. package/dist/alignString.js.flow +0 -97
  35. package/dist/alignString.js.map +0 -1
  36. package/dist/alignTableData.js +0 -35
  37. package/dist/alignTableData.js.flow +0 -21
  38. package/dist/alignTableData.js.map +0 -1
  39. package/dist/calculateCellHeight.js +0 -38
  40. package/dist/calculateCellHeight.js.flow +0 -24
  41. package/dist/calculateCellHeight.js.map +0 -1
  42. package/dist/calculateCellWidthIndex.js +0 -28
  43. package/dist/calculateCellWidthIndex.js.flow +0 -17
  44. package/dist/calculateCellWidthIndex.js.map +0 -1
  45. package/dist/calculateMaximumColumnWidthIndex.js +0 -37
  46. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  47. package/dist/calculateMaximumColumnWidthIndex.js.map +0 -1
  48. package/dist/calculateRowHeightIndex.js +0 -46
  49. package/dist/calculateRowHeightIndex.js.flow +0 -36
  50. package/dist/calculateRowHeightIndex.js.map +0 -1
  51. package/dist/createStream.js +0 -125
  52. package/dist/createStream.js.flow +0 -125
  53. package/dist/createStream.js.map +0 -1
  54. package/dist/drawBorder.js +0 -110
  55. package/dist/drawBorder.js.flow +0 -101
  56. package/dist/drawBorder.js.map +0 -1
  57. package/dist/drawRow.js +0 -26
  58. package/dist/drawRow.js.flow +0 -15
  59. package/dist/drawRow.js.map +0 -1
  60. package/dist/drawTable.js +0 -59
  61. package/dist/drawTable.js.flow +0 -53
  62. package/dist/drawTable.js.map +0 -1
  63. package/dist/getBorderCharacters.js +0 -119
  64. package/dist/getBorderCharacters.js.flow +0 -120
  65. package/dist/getBorderCharacters.js.map +0 -1
  66. package/dist/index.js +0 -32
  67. package/dist/index.js.map +0 -1
  68. package/dist/makeConfig.js +0 -92
  69. package/dist/makeConfig.js.flow +0 -76
  70. package/dist/makeConfig.js.map +0 -1
  71. package/dist/makeStreamConfig.js +0 -98
  72. package/dist/makeStreamConfig.js.flow +0 -83
  73. package/dist/makeStreamConfig.js.map +0 -1
  74. package/dist/mapDataUsingRowHeightIndex.js +0 -42
  75. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  76. package/dist/mapDataUsingRowHeightIndex.js.map +0 -1
  77. package/dist/padTableData.js +0 -24
  78. package/dist/padTableData.js.flow +0 -14
  79. package/dist/padTableData.js.map +0 -1
  80. package/dist/schemas/config.json +0 -23
  81. package/dist/schemas/shared.json +0 -98
  82. package/dist/schemas/streamConfig.json +0 -20
  83. package/dist/stringifyTableData.js +0 -22
  84. package/dist/stringifyTableData.js.flow +0 -11
  85. package/dist/stringifyTableData.js.map +0 -1
  86. package/dist/table.js +0 -110
  87. package/dist/table.js.flow +0 -96
  88. package/dist/table.js.map +0 -1
  89. package/dist/truncateTableData.js +0 -30
  90. package/dist/truncateTableData.js.flow +0 -17
  91. package/dist/truncateTableData.js.map +0 -1
  92. package/dist/validateConfig.js +0 -41
  93. package/dist/validateConfig.js.flow +0 -27
  94. package/dist/validateConfig.js.map +0 -1
  95. package/dist/validateTableData.js +0 -55
  96. package/dist/validateTableData.js.flow +0 -44
  97. package/dist/validateTableData.js.map +0 -1
  98. package/dist/wrapCell.js +0 -48
  99. package/dist/wrapCell.js.flow +0 -35
  100. package/dist/wrapCell.js.map +0 -1
  101. package/dist/wrapString.js +0 -40
  102. package/dist/wrapString.js.flow +0 -29
  103. package/dist/wrapString.js.map +0 -1
  104. package/dist/wrapWord.js +0 -47
  105. package/dist/wrapWord.js.flow +0 -39
  106. package/dist/wrapWord.js.map +0 -1
package/package.json CHANGED
@@ -17,33 +17,34 @@
17
17
  },
18
18
  "description": "Formats data into a string table.",
19
19
  "devDependencies": {
20
- "@babel/cli": "^7.12.10",
21
- "@babel/core": "^7.12.10",
22
- "@babel/node": "^7.12.10",
23
- "@babel/plugin-transform-flow-strip-types": "^7.12.10",
24
- "@babel/preset-env": "^7.12.11",
25
- "@babel/register": "^7.12.10",
20
+ "@types/chai": "^4.2.16",
21
+ "@types/lodash.clonedeep": "^4.5.6",
22
+ "@types/lodash.flatten": "^4.4.6",
23
+ "@types/lodash.mapvalues": "^4.6.6",
24
+ "@types/lodash.truncate": "^4.4.6",
25
+ "@types/mocha": "^8.2.2",
26
+ "@types/node": "^14.14.37",
27
+ "@types/sinon": "^10.0.0",
28
+ "@types/slice-ansi": "^4.0.0",
26
29
  "ajv-cli": "^5.0.0",
27
30
  "ajv-keywords": "^5.0.0",
28
- "babel-plugin-istanbul": "^6.0.0",
29
- "babel-plugin-transform-export-default-name": "^2.1.0",
30
31
  "chai": "^4.2.0",
31
32
  "chalk": "^4.1.0",
32
33
  "coveralls": "^3.1.0",
33
34
  "eslint": "^7.16.0",
34
35
  "eslint-config-canonical": "^25.0.0",
35
- "flow-bin": "^0.141.0",
36
- "flow-copy-source": "^2.0.9",
37
36
  "gitdown": "^3.1.3",
38
37
  "husky": "^4.3.6",
39
38
  "js-beautify": "^1.13.0",
40
39
  "lodash.mapvalues": "^4.6.0",
41
40
  "lodash.random": "^3.2.0",
42
41
  "lodash.sample": "^4.2.1",
42
+ "mkdirp": "^1.0.4",
43
43
  "mocha": "^8.2.1",
44
44
  "nyc": "^15.1.0",
45
45
  "semantic-release": "^17.3.1",
46
- "sinon": "^9.2.2"
46
+ "sinon": "^9.2.2",
47
+ "typescript": "4.2.4"
47
48
  },
48
49
  "engines": {
49
50
  "node": ">=10.0.0"
@@ -51,7 +52,7 @@
51
52
  "husky": {
52
53
  "hooks": {
53
54
  "post-commit": "npm run create-readme && git add README.md && git commit -m 'docs: generate docs' --no-verify",
54
- "pre-commit": "npm run lint && npm run test && npm run build"
55
+ "pre-commit": "npm run build && npm run lint && npm run test"
55
56
  }
56
57
  },
57
58
  "keywords": [
@@ -62,31 +63,37 @@
62
63
  "ansi"
63
64
  ],
64
65
  "license": "BSD-3-Clause",
65
- "main": "./dist/index.js",
66
+ "main": "./dist/src/index.js",
67
+ "files": [
68
+ "dist/src/**/*.js",
69
+ "dist/src/types/api.d.ts",
70
+ "dist/src/index.d.ts"
71
+ ],
66
72
  "name": "table",
67
73
  "nyc": {
68
- "include": [
69
- "src/**/*.js"
74
+ "extensions": [
75
+ ".ts"
76
+ ],
77
+ "exclude": [
78
+ "dist/src/validators.js",
79
+ "test/**/*.ts"
70
80
  ],
71
- "instrument": false,
72
81
  "reporter": [
73
82
  "text-lcov"
74
- ],
75
- "require": [
76
- "@babel/register"
77
- ],
78
- "sourceMap": false
83
+ ]
79
84
  },
80
85
  "repository": {
81
86
  "type": "git",
82
87
  "url": "https://github.com/gajus/table"
83
88
  },
84
89
  "scripts": {
85
- "build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && npm run create-validators && flow-copy-source src dist",
90
+ "compile": "tsc",
91
+ "prebuild": "rm -fr ./dist && mkdirp dist/src",
92
+ "build": "npm run create-validators && npm run compile",
86
93
  "create-readme": "gitdown ./.README/README.md --output-file ./README.md",
87
- "create-validators": "ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > dist/validators.js",
88
- "lint": "npm run build && eslint ./src ./test && flow",
89
- "test": "mocha --require @babel/register"
94
+ "create-validators": "ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > dist/src/validators.js",
95
+ "lint": "eslint ./src ./test",
96
+ "test": "mocha ./dist/test/**/*.js"
90
97
  },
91
- "version": "6.0.8"
98
+ "version": "6.3.0"
92
99
  }
@@ -1,108 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _isNumberObject = _interopRequireDefault(require("is-number-object"));
9
-
10
- var _isString = _interopRequireDefault(require("is-string"));
11
-
12
- var _stringWidth = _interopRequireDefault(require("string-width"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const alignments = ['left', 'right', 'center'];
17
- /**
18
- * @param {string} subject
19
- * @param {number} width
20
- * @returns {string}
21
- */
22
-
23
- const alignLeft = (subject, width) => {
24
- return subject + ' '.repeat(width);
25
- };
26
- /**
27
- * @param {string} subject
28
- * @param {number} width
29
- * @returns {string}
30
- */
31
-
32
-
33
- const alignRight = (subject, width) => {
34
- return ' '.repeat(width) + subject;
35
- };
36
- /**
37
- * @param {string} subject
38
- * @param {number} width
39
- * @returns {string}
40
- */
41
-
42
-
43
- const alignCenter = (subject, width) => {
44
- let halfWidth;
45
- halfWidth = width / 2;
46
-
47
- if (width % 2 === 0) {
48
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
49
- } else {
50
- halfWidth = Math.floor(halfWidth);
51
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
52
- }
53
- };
54
- /**
55
- * Pads a string to the left and/or right to position the subject
56
- * text in a desired alignment within a container.
57
- *
58
- * @param {string} subject
59
- * @param {number} containerWidth
60
- * @param {string} alignment One of the valid options (left, right, center).
61
- * @returns {string}
62
- */
63
-
64
-
65
- const alignString = (subject, containerWidth, alignment) => {
66
- if (!(0, _isString.default)(subject)) {
67
- throw new TypeError('Subject parameter value must be a string.');
68
- }
69
-
70
- if (!(0, _isNumberObject.default)(containerWidth)) {
71
- throw new TypeError('Container width parameter value must be a number.');
72
- }
73
-
74
- const subjectWidth = (0, _stringWidth.default)(subject);
75
-
76
- if (subjectWidth > containerWidth) {
77
- // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
78
- throw new Error('Subject parameter value width cannot be greater than the container width.');
79
- }
80
-
81
- if (!(0, _isString.default)(alignment)) {
82
- throw new TypeError('Alignment parameter value must be a string.');
83
- }
84
-
85
- if (!alignments.includes(alignment)) {
86
- throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
87
- }
88
-
89
- if (subjectWidth === 0) {
90
- return ' '.repeat(containerWidth);
91
- }
92
-
93
- const availableWidth = containerWidth - subjectWidth;
94
-
95
- if (alignment === 'left') {
96
- return alignLeft(subject, availableWidth);
97
- }
98
-
99
- if (alignment === 'right') {
100
- return alignRight(subject, availableWidth);
101
- }
102
-
103
- return alignCenter(subject, availableWidth);
104
- };
105
-
106
- var _default = alignString;
107
- exports.default = _default;
108
- //# sourceMappingURL=alignString.js.map
@@ -1,97 +0,0 @@
1
- import isNumber from 'is-number-object';
2
- import isString from 'is-string';
3
- import stringWidth from 'string-width';
4
-
5
- const alignments = [
6
- 'left',
7
- 'right',
8
- 'center',
9
- ];
10
-
11
- /**
12
- * @param {string} subject
13
- * @param {number} width
14
- * @returns {string}
15
- */
16
- const alignLeft = (subject, width) => {
17
- return subject + ' '.repeat(width);
18
- };
19
-
20
- /**
21
- * @param {string} subject
22
- * @param {number} width
23
- * @returns {string}
24
- */
25
- const alignRight = (subject, width) => {
26
- return ' '.repeat(width) + subject;
27
- };
28
-
29
- /**
30
- * @param {string} subject
31
- * @param {number} width
32
- * @returns {string}
33
- */
34
- const alignCenter = (subject, width) => {
35
- let halfWidth;
36
-
37
- halfWidth = width / 2;
38
-
39
- if (width % 2 === 0) {
40
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
41
- } else {
42
- halfWidth = Math.floor(halfWidth);
43
-
44
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
45
- }
46
- };
47
-
48
- /**
49
- * Pads a string to the left and/or right to position the subject
50
- * text in a desired alignment within a container.
51
- *
52
- * @param {string} subject
53
- * @param {number} containerWidth
54
- * @param {string} alignment One of the valid options (left, right, center).
55
- * @returns {string}
56
- */
57
- export default (subject, containerWidth, alignment) => {
58
- if (!isString(subject)) {
59
- throw new TypeError('Subject parameter value must be a string.');
60
- }
61
-
62
- if (!isNumber(containerWidth)) {
63
- throw new TypeError('Container width parameter value must be a number.');
64
- }
65
-
66
- const subjectWidth = stringWidth(subject);
67
-
68
- if (subjectWidth > containerWidth) {
69
- // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
70
-
71
- throw new Error('Subject parameter value width cannot be greater than the container width.');
72
- }
73
-
74
- if (!isString(alignment)) {
75
- throw new TypeError('Alignment parameter value must be a string.');
76
- }
77
-
78
- if (!alignments.includes(alignment)) {
79
- throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
80
- }
81
-
82
- if (subjectWidth === 0) {
83
- return ' '.repeat(containerWidth);
84
- }
85
-
86
- const availableWidth = containerWidth - subjectWidth;
87
-
88
- if (alignment === 'left') {
89
- return alignLeft(subject, availableWidth);
90
- }
91
-
92
- if (alignment === 'right') {
93
- return alignRight(subject, availableWidth);
94
- }
95
-
96
- return alignCenter(subject, availableWidth);
97
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/alignString.js"],"names":["alignments","alignLeft","subject","width","repeat","alignRight","alignCenter","halfWidth","Math","floor","containerWidth","alignment","TypeError","subjectWidth","Error","includes","availableWidth"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA,MAAMA,UAAU,GAAG,CACjB,MADiB,EAEjB,OAFiB,EAGjB,QAHiB,CAAnB;AAMA;AACA;AACA;AACA;AACA;;AACA,MAAMC,SAAS,GAAG,CAACC,OAAD,EAAUC,KAAV,KAAoB;AACpC,SAAOD,OAAO,GAAG,IAAIE,MAAJ,CAAWD,KAAX,CAAjB;AACD,CAFD;AAIA;AACA;AACA;AACA;AACA;;;AACA,MAAME,UAAU,GAAG,CAACH,OAAD,EAAUC,KAAV,KAAoB;AACrC,SAAO,IAAIC,MAAJ,CAAWD,KAAX,IAAoBD,OAA3B;AACD,CAFD;AAIA;AACA;AACA;AACA;AACA;;;AACA,MAAMI,WAAW,GAAG,CAACJ,OAAD,EAAUC,KAAV,KAAoB;AACtC,MAAII,SAAJ;AAEAA,EAAAA,SAAS,GAAGJ,KAAK,GAAG,CAApB;;AAEA,MAAIA,KAAK,GAAG,CAAR,KAAc,CAAlB,EAAqB;AACnB,WAAO,IAAIC,MAAJ,CAAWG,SAAX,IAAwBL,OAAxB,GAAkC,IAAIE,MAAJ,CAAWG,SAAX,CAAzC;AACD,GAFD,MAEO;AACLA,IAAAA,SAAS,GAAGC,IAAI,CAACC,KAAL,CAAWF,SAAX,CAAZ;AAEA,WAAO,IAAIH,MAAJ,CAAWG,SAAX,IAAwBL,OAAxB,GAAkC,IAAIE,MAAJ,CAAWG,SAAS,GAAG,CAAvB,CAAzC;AACD;AACF,CAZD;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;qBACgBL,O,EAASQ,c,EAAgBC,S,KAAc;AACrD,MAAI,CAAC,uBAAST,OAAT,CAAL,EAAwB;AACtB,UAAM,IAAIU,SAAJ,CAAc,2CAAd,CAAN;AACD;;AAED,MAAI,CAAC,6BAASF,cAAT,CAAL,EAA+B;AAC7B,UAAM,IAAIE,SAAJ,CAAc,mDAAd,CAAN;AACD;;AAED,QAAMC,YAAY,GAAG,0BAAYX,OAAZ,CAArB;;AAEA,MAAIW,YAAY,GAAGH,cAAnB,EAAmC;AACjC;AAEA,UAAM,IAAII,KAAJ,CAAU,2EAAV,CAAN;AACD;;AAED,MAAI,CAAC,uBAASH,SAAT,CAAL,EAA0B;AACxB,UAAM,IAAIC,SAAJ,CAAc,6CAAd,CAAN;AACD;;AAED,MAAI,CAACZ,UAAU,CAACe,QAAX,CAAoBJ,SAApB,CAAL,EAAqC;AACnC,UAAM,IAAIG,KAAJ,CAAU,4FAAV,CAAN;AACD;;AAED,MAAID,YAAY,KAAK,CAArB,EAAwB;AACtB,WAAO,IAAIT,MAAJ,CAAWM,cAAX,CAAP;AACD;;AAED,QAAMM,cAAc,GAAGN,cAAc,GAAGG,YAAxC;;AAEA,MAAIF,SAAS,KAAK,MAAlB,EAA0B;AACxB,WAAOV,SAAS,CAACC,OAAD,EAAUc,cAAV,CAAhB;AACD;;AAED,MAAIL,SAAS,KAAK,OAAlB,EAA2B;AACzB,WAAON,UAAU,CAACH,OAAD,EAAUc,cAAV,CAAjB;AACD;;AAED,SAAOV,WAAW,CAACJ,OAAD,EAAUc,cAAV,CAAlB;AACD,C","sourcesContent":["import isNumber from 'is-number-object';\nimport isString from 'is-string';\nimport stringWidth from 'string-width';\n\nconst alignments = [\n 'left',\n 'right',\n 'center',\n];\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignLeft = (subject, width) => {\n return subject + ' '.repeat(width);\n};\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignRight = (subject, width) => {\n return ' '.repeat(width) + subject;\n};\n\n/**\n * @param {string} subject\n * @param {number} width\n * @returns {string}\n */\nconst alignCenter = (subject, width) => {\n let halfWidth;\n\n halfWidth = width / 2;\n\n if (width % 2 === 0) {\n return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);\n } else {\n halfWidth = Math.floor(halfWidth);\n\n return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);\n }\n};\n\n/**\n * Pads a string to the left and/or right to position the subject\n * text in a desired alignment within a container.\n *\n * @param {string} subject\n * @param {number} containerWidth\n * @param {string} alignment One of the valid options (left, right, center).\n * @returns {string}\n */\nexport default (subject, containerWidth, alignment) => {\n if (!isString(subject)) {\n throw new TypeError('Subject parameter value must be a string.');\n }\n\n if (!isNumber(containerWidth)) {\n throw new TypeError('Container width parameter value must be a number.');\n }\n\n const subjectWidth = stringWidth(subject);\n\n if (subjectWidth > containerWidth) {\n // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);\n\n throw new Error('Subject parameter value width cannot be greater than the container width.');\n }\n\n if (!isString(alignment)) {\n throw new TypeError('Alignment parameter value must be a string.');\n }\n\n if (!alignments.includes(alignment)) {\n throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');\n }\n\n if (subjectWidth === 0) {\n return ' '.repeat(containerWidth);\n }\n\n const availableWidth = containerWidth - subjectWidth;\n\n if (alignment === 'left') {\n return alignLeft(subject, availableWidth);\n }\n\n if (alignment === 'right') {\n return alignRight(subject, availableWidth);\n }\n\n return alignCenter(subject, availableWidth);\n};\n"],"file":"alignString.js"}
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _stringWidth = _interopRequireDefault(require("string-width"));
9
-
10
- var _alignString = _interopRequireDefault(require("./alignString"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * @param {table~row[]} rows
16
- * @param {object} config
17
- * @returns {table~row[]}
18
- */
19
- const alignTableData = (rows, config) => {
20
- return rows.map(cells => {
21
- return cells.map((value, index1) => {
22
- const column = config.columns[index1];
23
-
24
- if ((0, _stringWidth.default)(value) === column.width) {
25
- return value;
26
- } else {
27
- return (0, _alignString.default)(value, column.width, column.alignment);
28
- }
29
- });
30
- });
31
- };
32
-
33
- var _default = alignTableData;
34
- exports.default = _default;
35
- //# sourceMappingURL=alignTableData.js.map
@@ -1,21 +0,0 @@
1
- import stringWidth from 'string-width';
2
- import alignString from './alignString';
3
-
4
- /**
5
- * @param {table~row[]} rows
6
- * @param {object} config
7
- * @returns {table~row[]}
8
- */
9
- export default (rows, config) => {
10
- return rows.map((cells) => {
11
- return cells.map((value, index1) => {
12
- const column = config.columns[index1];
13
-
14
- if (stringWidth(value) === column.width) {
15
- return value;
16
- } else {
17
- return alignString(value, column.width, column.alignment);
18
- }
19
- });
20
- });
21
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/alignTableData.js"],"names":["rows","config","map","cells","value","index1","column","columns","width","alignment"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;wBACgBA,I,EAAMC,M,KAAW;AAC/B,SAAOD,IAAI,CAACE,GAAL,CAAUC,KAAD,IAAW;AACzB,WAAOA,KAAK,CAACD,GAAN,CAAU,CAACE,KAAD,EAAQC,MAAR,KAAmB;AAClC,YAAMC,MAAM,GAAGL,MAAM,CAACM,OAAP,CAAeF,MAAf,CAAf;;AAEA,UAAI,0BAAYD,KAAZ,MAAuBE,MAAM,CAACE,KAAlC,EAAyC;AACvC,eAAOJ,KAAP;AACD,OAFD,MAEO;AACL,eAAO,0BAAYA,KAAZ,EAAmBE,MAAM,CAACE,KAA1B,EAAiCF,MAAM,CAACG,SAAxC,CAAP;AACD;AACF,KARM,CAAP;AASD,GAVM,CAAP;AAWD,C","sourcesContent":["import stringWidth from 'string-width';\nimport alignString from './alignString';\n\n/**\n * @param {table~row[]} rows\n * @param {object} config\n * @returns {table~row[]}\n */\nexport default (rows, config) => {\n return rows.map((cells) => {\n return cells.map((value, index1) => {\n const column = config.columns[index1];\n\n if (stringWidth(value) === column.width) {\n return value;\n } else {\n return alignString(value, column.width, column.alignment);\n }\n });\n });\n};\n"],"file":"alignTableData.js"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _isString = _interopRequireDefault(require("is-string"));
9
-
10
- var _wrapCell = _interopRequireDefault(require("./wrapCell"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * @param {string} value
16
- * @param {number} columnWidth
17
- * @param {boolean} useWrapWord
18
- * @returns {number}
19
- */
20
- const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
21
- if (!(0, _isString.default)(value)) {
22
- throw new TypeError('Value must be a string.');
23
- }
24
-
25
- if (!Number.isInteger(columnWidth)) {
26
- throw new TypeError('Column width must be an integer.');
27
- }
28
-
29
- if (columnWidth < 1) {
30
- throw new Error('Column width must be greater than 0.');
31
- }
32
-
33
- return (0, _wrapCell.default)(value, columnWidth, useWrapWord).length;
34
- };
35
-
36
- var _default = calculateCellHeight;
37
- exports.default = _default;
38
- //# sourceMappingURL=calculateCellHeight.js.map
@@ -1,24 +0,0 @@
1
- import isString from 'is-string';
2
- import wrapCell from './wrapCell';
3
-
4
- /**
5
- * @param {string} value
6
- * @param {number} columnWidth
7
- * @param {boolean} useWrapWord
8
- * @returns {number}
9
- */
10
- export default (value, columnWidth, useWrapWord = false) => {
11
- if (!isString(value)) {
12
- throw new TypeError('Value must be a string.');
13
- }
14
-
15
- if (!Number.isInteger(columnWidth)) {
16
- throw new TypeError('Column width must be an integer.');
17
- }
18
-
19
- if (columnWidth < 1) {
20
- throw new Error('Column width must be greater than 0.');
21
- }
22
-
23
- return wrapCell(value, columnWidth, useWrapWord).length;
24
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/calculateCellHeight.js"],"names":["value","columnWidth","useWrapWord","TypeError","Number","isInteger","Error","length"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;6BACgBA,K,EAAOC,W,EAAaC,WAAW,GAAG,K,KAAU;AAC1D,MAAI,CAAC,uBAASF,KAAT,CAAL,EAAsB;AACpB,UAAM,IAAIG,SAAJ,CAAc,yBAAd,CAAN;AACD;;AAED,MAAI,CAACC,MAAM,CAACC,SAAP,CAAiBJ,WAAjB,CAAL,EAAoC;AAClC,UAAM,IAAIE,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,MAAIF,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAM,IAAIK,KAAJ,CAAU,sCAAV,CAAN;AACD;;AAED,SAAO,uBAASN,KAAT,EAAgBC,WAAhB,EAA6BC,WAA7B,EAA0CK,MAAjD;AACD,C","sourcesContent":["import isString from 'is-string';\nimport wrapCell from './wrapCell';\n\n/**\n * @param {string} value\n * @param {number} columnWidth\n * @param {boolean} useWrapWord\n * @returns {number}\n */\nexport default (value, columnWidth, useWrapWord = false) => {\n if (!isString(value)) {\n throw new TypeError('Value must be a string.');\n }\n\n if (!Number.isInteger(columnWidth)) {\n throw new TypeError('Column width must be an integer.');\n }\n\n if (columnWidth < 1) {\n throw new Error('Column width must be greater than 0.');\n }\n\n return wrapCell(value, columnWidth, useWrapWord).length;\n};\n"],"file":"calculateCellHeight.js"}
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _stringWidth = _interopRequireDefault(require("string-width"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * Calculates width of each cell contents.
14
- *
15
- * @param {string[]} cells
16
- * @returns {number[]}
17
- */
18
- const calculateCellWidthIndex = cells => {
19
- return cells.map(value => {
20
- return Math.max(...value.split('\n').map(line => {
21
- return (0, _stringWidth.default)(line);
22
- }));
23
- });
24
- };
25
-
26
- var _default = calculateCellWidthIndex;
27
- exports.default = _default;
28
- //# sourceMappingURL=calculateCellWidthIndex.js.map
@@ -1,17 +0,0 @@
1
- import stringWidth from 'string-width';
2
-
3
- /**
4
- * Calculates width of each cell contents.
5
- *
6
- * @param {string[]} cells
7
- * @returns {number[]}
8
- */
9
- export default (cells) => {
10
- return cells.map((value) => {
11
- return Math.max(
12
- ...value.split('\n').map((line) => {
13
- return stringWidth(line);
14
- }),
15
- );
16
- });
17
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/calculateCellWidthIndex.js"],"names":["cells","map","value","Math","max","split","line"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;gCACgBA,K,IAAU;AACxB,SAAOA,KAAK,CAACC,GAAN,CAAWC,KAAD,IAAW;AAC1B,WAAOC,IAAI,CAACC,GAAL,CACL,GAAGF,KAAK,CAACG,KAAN,CAAY,IAAZ,EAAkBJ,GAAlB,CAAuBK,IAAD,IAAU;AACjC,aAAO,0BAAYA,IAAZ,CAAP;AACD,KAFE,CADE,CAAP;AAKD,GANM,CAAP;AAOD,C","sourcesContent":["import stringWidth from 'string-width';\n\n/**\n * Calculates width of each cell contents.\n *\n * @param {string[]} cells\n * @returns {number[]}\n */\nexport default (cells) => {\n return cells.map((value) => {\n return Math.max(\n ...value.split('\\n').map((line) => {\n return stringWidth(line);\n }),\n );\n });\n};\n"],"file":"calculateCellWidthIndex.js"}
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * Produces an array of values that describe the largest value length (width) in every column.
14
- *
15
- * @param {Array[]} rows
16
- * @returns {number[]}
17
- */
18
- const calculateMaximumColumnWidthIndex = rows => {
19
- if (!rows[0]) {
20
- throw new Error('Dataset must have at least one row.');
21
- }
22
-
23
- const columns = new Array(rows[0].length).fill(0);
24
- rows.forEach(row => {
25
- const columnWidthIndex = (0, _calculateCellWidthIndex.default)(row);
26
- columnWidthIndex.forEach((valueWidth, index0) => {
27
- if (columns[index0] < valueWidth) {
28
- columns[index0] = valueWidth;
29
- }
30
- });
31
- });
32
- return columns;
33
- };
34
-
35
- var _default = calculateMaximumColumnWidthIndex;
36
- exports.default = _default;
37
- //# sourceMappingURL=calculateMaximumColumnWidthIndex.js.map
@@ -1,27 +0,0 @@
1
- import calculateCellWidthIndex from './calculateCellWidthIndex';
2
-
3
- /**
4
- * Produces an array of values that describe the largest value length (width) in every column.
5
- *
6
- * @param {Array[]} rows
7
- * @returns {number[]}
8
- */
9
- export default (rows) => {
10
- if (!rows[0]) {
11
- throw new Error('Dataset must have at least one row.');
12
- }
13
-
14
- const columns = new Array(rows[0].length).fill(0);
15
-
16
- rows.forEach((row) => {
17
- const columnWidthIndex = calculateCellWidthIndex(row);
18
-
19
- columnWidthIndex.forEach((valueWidth, index0) => {
20
- if (columns[index0] < valueWidth) {
21
- columns[index0] = valueWidth;
22
- }
23
- });
24
- });
25
-
26
- return columns;
27
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/calculateMaximumColumnWidthIndex.js"],"names":["rows","Error","columns","Array","length","fill","forEach","row","columnWidthIndex","valueWidth","index0"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;yCACgBA,I,IAAS;AACvB,MAAI,CAACA,IAAI,CAAC,CAAD,CAAT,EAAc;AACZ,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,QAAMC,OAAO,GAAG,IAAIC,KAAJ,CAAUH,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAlB,EAA0BC,IAA1B,CAA+B,CAA/B,CAAhB;AAEAL,EAAAA,IAAI,CAACM,OAAL,CAAcC,GAAD,IAAS;AACpB,UAAMC,gBAAgB,GAAG,sCAAwBD,GAAxB,CAAzB;AAEAC,IAAAA,gBAAgB,CAACF,OAAjB,CAAyB,CAACG,UAAD,EAAaC,MAAb,KAAwB;AAC/C,UAAIR,OAAO,CAACQ,MAAD,CAAP,GAAkBD,UAAtB,EAAkC;AAChCP,QAAAA,OAAO,CAACQ,MAAD,CAAP,GAAkBD,UAAlB;AACD;AACF,KAJD;AAKD,GARD;AAUA,SAAOP,OAAP;AACD,C","sourcesContent":["import calculateCellWidthIndex from './calculateCellWidthIndex';\n\n/**\n * Produces an array of values that describe the largest value length (width) in every column.\n *\n * @param {Array[]} rows\n * @returns {number[]}\n */\nexport default (rows) => {\n if (!rows[0]) {\n throw new Error('Dataset must have at least one row.');\n }\n\n const columns = new Array(rows[0].length).fill(0);\n\n rows.forEach((row) => {\n const columnWidthIndex = calculateCellWidthIndex(row);\n\n columnWidthIndex.forEach((valueWidth, index0) => {\n if (columns[index0] < valueWidth) {\n columns[index0] = valueWidth;\n }\n });\n });\n\n return columns;\n};\n"],"file":"calculateMaximumColumnWidthIndex.js"}
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _isBooleanObject = _interopRequireDefault(require("is-boolean-object"));
9
-
10
- var _isNumberObject = _interopRequireDefault(require("is-number-object"));
11
-
12
- var _calculateCellHeight = _interopRequireDefault(require("./calculateCellHeight"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- /**
17
- * Calculates the vertical row span index.
18
- *
19
- * @param {Array[]} rows
20
- * @param {object} config
21
- * @returns {number[]}
22
- */
23
- const calculateRowHeightIndex = (rows, config) => {
24
- const tableWidth = rows[0].length;
25
- const rowSpanIndex = [];
26
- rows.forEach(cells => {
27
- const cellHeightIndex = new Array(tableWidth).fill(1);
28
- cells.forEach((value, index1) => {
29
- if (!(0, _isNumberObject.default)(config.columns[index1].width)) {
30
- throw new TypeError('column[index].width must be a number.');
31
- }
32
-
33
- if (!(0, _isBooleanObject.default)(config.columns[index1].wrapWord)) {
34
- throw new TypeError('column[index].wrapWord must be a boolean.');
35
- }
36
-
37
- cellHeightIndex[index1] = (0, _calculateCellHeight.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
38
- });
39
- rowSpanIndex.push(Math.max(...cellHeightIndex));
40
- });
41
- return rowSpanIndex;
42
- };
43
-
44
- var _default = calculateRowHeightIndex;
45
- exports.default = _default;
46
- //# sourceMappingURL=calculateRowHeightIndex.js.map
@@ -1,36 +0,0 @@
1
- import isBoolean from 'is-boolean-object';
2
- import isNumber from 'is-number-object';
3
- import calculateCellHeight from './calculateCellHeight';
4
-
5
- /**
6
- * Calculates the vertical row span index.
7
- *
8
- * @param {Array[]} rows
9
- * @param {object} config
10
- * @returns {number[]}
11
- */
12
- export default (rows, config) => {
13
- const tableWidth = rows[0].length;
14
-
15
- const rowSpanIndex = [];
16
-
17
- rows.forEach((cells) => {
18
- const cellHeightIndex = new Array(tableWidth).fill(1);
19
-
20
- cells.forEach((value, index1) => {
21
- if (!isNumber(config.columns[index1].width)) {
22
- throw new TypeError('column[index].width must be a number.');
23
- }
24
-
25
- if (!isBoolean(config.columns[index1].wrapWord)) {
26
- throw new TypeError('column[index].wrapWord must be a boolean.');
27
- }
28
-
29
- cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
30
- });
31
-
32
- rowSpanIndex.push(Math.max(...cellHeightIndex));
33
- });
34
-
35
- return rowSpanIndex;
36
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/calculateRowHeightIndex.js"],"names":["rows","config","tableWidth","length","rowSpanIndex","forEach","cells","cellHeightIndex","Array","fill","value","index1","columns","width","TypeError","wrapWord","push","Math","max"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;iCACgBA,I,EAAMC,M,KAAW;AAC/B,QAAMC,UAAU,GAAGF,IAAI,CAAC,CAAD,CAAJ,CAAQG,MAA3B;AAEA,QAAMC,YAAY,GAAG,EAArB;AAEAJ,EAAAA,IAAI,CAACK,OAAL,CAAcC,KAAD,IAAW;AACtB,UAAMC,eAAe,GAAG,IAAIC,KAAJ,CAAUN,UAAV,EAAsBO,IAAtB,CAA2B,CAA3B,CAAxB;AAEAH,IAAAA,KAAK,CAACD,OAAN,CAAc,CAACK,KAAD,EAAQC,MAAR,KAAmB;AAC/B,UAAI,CAAC,6BAASV,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBE,KAAhC,CAAL,EAA6C;AAC3C,cAAM,IAAIC,SAAJ,CAAc,uCAAd,CAAN;AACD;;AAED,UAAI,CAAC,8BAAUb,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBI,QAAjC,CAAL,EAAiD;AAC/C,cAAM,IAAID,SAAJ,CAAc,2CAAd,CAAN;AACD;;AAEDP,MAAAA,eAAe,CAACI,MAAD,CAAf,GAA0B,kCAAoBD,KAApB,EAA2BT,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBE,KAAlD,EAAyDZ,MAAM,CAACW,OAAP,CAAeD,MAAf,EAAuBI,QAAhF,CAA1B;AACD,KAVD;AAYAX,IAAAA,YAAY,CAACY,IAAb,CAAkBC,IAAI,CAACC,GAAL,CAAS,GAAGX,eAAZ,CAAlB;AACD,GAhBD;AAkBA,SAAOH,YAAP;AACD,C","sourcesContent":["import isBoolean from 'is-boolean-object';\nimport isNumber from 'is-number-object';\nimport calculateCellHeight from './calculateCellHeight';\n\n/**\n * Calculates the vertical row span index.\n *\n * @param {Array[]} rows\n * @param {object} config\n * @returns {number[]}\n */\nexport default (rows, config) => {\n const tableWidth = rows[0].length;\n\n const rowSpanIndex = [];\n\n rows.forEach((cells) => {\n const cellHeightIndex = new Array(tableWidth).fill(1);\n\n cells.forEach((value, index1) => {\n if (!isNumber(config.columns[index1].width)) {\n throw new TypeError('column[index].width must be a number.');\n }\n\n if (!isBoolean(config.columns[index1].wrapWord)) {\n throw new TypeError('column[index].wrapWord must be a boolean.');\n }\n\n cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);\n });\n\n rowSpanIndex.push(Math.max(...cellHeightIndex));\n });\n\n return rowSpanIndex;\n};\n"],"file":"calculateRowHeightIndex.js"}