table 5.1.0 → 5.2.2

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.
@@ -7,9 +7,7 @@ exports.default = void 0;
7
7
 
8
8
  var _lodash = _interopRequireDefault(require("lodash"));
9
9
 
10
- var _stringWidth = _interopRequireDefault(require("string-width"));
11
-
12
- var _wrapWord = _interopRequireDefault(require("./wrapWord"));
10
+ var _wrapCell = _interopRequireDefault(require("./wrapCell"));
13
11
 
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
@@ -32,11 +30,7 @@ const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
32
30
  throw new Error('Column width must be greater than 0.');
33
31
  }
34
32
 
35
- if (useWrapWord) {
36
- return (0, _wrapWord.default)(value, columnWidth).length;
37
- }
38
-
39
- return Math.ceil((0, _stringWidth.default)(value) / columnWidth);
33
+ return (0, _wrapCell.default)(value, columnWidth, useWrapWord).length;
40
34
  };
41
35
 
42
36
  var _default = calculateCellHeight;
@@ -1,6 +1,5 @@
1
1
  import _ from 'lodash';
2
- import stringWidth from 'string-width';
3
- import wrapWord from './wrapWord';
2
+ import wrapCell from './wrapCell';
4
3
 
5
4
  /**
6
5
  * @param {string} value
@@ -21,9 +20,5 @@ export default (value, columnWidth, useWrapWord = false) => {
21
20
  throw new Error('Column width must be greater than 0.');
22
21
  }
23
22
 
24
- if (useWrapWord) {
25
- return wrapWord(value, columnWidth).length;
26
- }
27
-
28
- return Math.ceil(stringWidth(value) / columnWidth);
23
+ return wrapCell(value, columnWidth, useWrapWord).length;
29
24
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/calculateCellHeight.js"],"names":["value","columnWidth","useWrapWord","_","isString","TypeError","Number","isInteger","Error","length","Math","ceil"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;;;;;;6BAMgBA,K,EAAOC,W,EAAaC,WAAW,GAAG,K,KAAU;AAC1D,MAAI,CAACC,gBAAEC,QAAF,CAAWJ,KAAX,CAAL,EAAwB;AACtB,UAAM,IAAIK,SAAJ,CAAc,yBAAd,CAAN;AACD;;AAED,MAAI,CAACC,MAAM,CAACC,SAAP,CAAiBN,WAAjB,CAAL,EAAoC;AAClC,UAAM,IAAII,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,MAAIJ,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAM,IAAIO,KAAJ,CAAU,sCAAV,CAAN;AACD;;AAED,MAAIN,WAAJ,EAAiB;AACf,WAAO,uBAASF,KAAT,EAAgBC,WAAhB,EAA6BQ,MAApC;AACD;;AAED,SAAOC,IAAI,CAACC,IAAL,CAAU,0BAAYX,KAAZ,IAAqBC,WAA/B,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport stringWidth from 'string-width';\nimport wrapWord from './wrapWord';\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 if (useWrapWord) {\n return wrapWord(value, columnWidth).length;\n }\n\n return Math.ceil(stringWidth(value) / columnWidth);\n};\n"],"file":"calculateCellHeight.js"}
1
+ {"version":3,"sources":["../src/calculateCellHeight.js"],"names":["value","columnWidth","useWrapWord","_","isString","TypeError","Number","isInteger","Error","length"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;;6BAMgBA,K,EAAOC,W,EAAaC,WAAW,GAAG,K,KAAU;AAC1D,MAAI,CAACC,gBAAEC,QAAF,CAAWJ,KAAX,CAAL,EAAwB;AACtB,UAAM,IAAIK,SAAJ,CAAc,yBAAd,CAAN;AACD;;AAED,MAAI,CAACC,MAAM,CAACC,SAAP,CAAiBN,WAAjB,CAAL,EAAoC;AAClC,UAAM,IAAII,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,MAAIJ,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAM,IAAIO,KAAJ,CAAU,sCAAV,CAAN;AACD;;AAED,SAAO,uBAASR,KAAT,EAAgBC,WAAhB,EAA6BC,WAA7B,EAA0CO,MAAjD;AACD,C","sourcesContent":["import _ from 'lodash';\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"}
@@ -7,9 +7,7 @@ exports.default = void 0;
7
7
 
8
8
  var _lodash = _interopRequireDefault(require("lodash"));
9
9
 
10
- var _wrapString = _interopRequireDefault(require("./wrapString"));
11
-
12
- var _wrapWord = _interopRequireDefault(require("./wrapWord"));
10
+ var _wrapCell = _interopRequireDefault(require("./wrapCell"));
13
11
 
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
@@ -30,16 +28,9 @@ const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => {
30
28
 
31
29
 
32
30
  cells.forEach((value, index1) => {
33
- let chunkedValue;
34
-
35
- if (config.columns[index1].wrapWord) {
36
- chunkedValue = (0, _wrapWord.default)(value, config.columns[index1].width);
37
- } else {
38
- chunkedValue = (0, _wrapString.default)(value, config.columns[index1].width);
39
- }
40
-
41
- chunkedValue.forEach((part, index2) => {
42
- rowHeight[index2][index1] = part;
31
+ const cellLines = (0, _wrapCell.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
32
+ cellLines.forEach((cellLine, index2) => {
33
+ rowHeight[index2][index1] = cellLine;
43
34
  });
44
35
  });
45
36
  return rowHeight;
@@ -1,6 +1,5 @@
1
1
  import _ from 'lodash';
2
- import wrapString from './wrapString';
3
- import wrapWord from './wrapWord';
2
+ import wrapCell from './wrapCell';
4
3
 
5
4
  /**
6
5
  * @param {Array} unmappedRows
@@ -21,16 +20,10 @@ export default (unmappedRows, rowHeightIndex, config) => {
21
20
  // [{cell index within a virtual row; index1}]
22
21
 
23
22
  cells.forEach((value, index1) => {
24
- let chunkedValue;
23
+ const cellLines = wrapCell(value, config.columns[index1].width, config.columns[index1].wrapWord);
25
24
 
26
- if (config.columns[index1].wrapWord) {
27
- chunkedValue = wrapWord(value, config.columns[index1].width);
28
- } else {
29
- chunkedValue = wrapString(value, config.columns[index1].width);
30
- }
31
-
32
- chunkedValue.forEach((part, index2) => {
33
- rowHeight[index2][index1] = part;
25
+ cellLines.forEach((cellLine, index2) => {
26
+ rowHeight[index2][index1] = cellLine;
34
27
  });
35
28
  });
36
29
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","_","times","Array","fill","forEach","value","index1","chunkedValue","columns","wrapWord","width","part","index2","flatten"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;;;;;;oCAMgBA,Y,EAAcC,c,EAAgBC,M,KAAW;AACvD,QAAMC,UAAU,GAAGH,YAAY,CAAC,CAAD,CAAZ,CAAgBI,MAAnC;AAEA,QAAMC,UAAU,GAAGL,YAAY,CAACM,GAAb,CAAiB,CAACC,KAAD,EAAQC,MAAR,KAAmB;AACrD,UAAMC,SAAS,GAAGC,gBAAEC,KAAF,CAAQV,cAAc,CAACO,MAAD,CAAtB,EAAgC,MAAM;AACtD,aAAO,IAAII,KAAJ,CAAUT,UAAV,EAAsBU,IAAtB,CAA2B,EAA3B,CAAP;AACD,KAFiB,CAAlB,CADqD,CAKrD;AACA;AACA;;;AAEAN,IAAAA,KAAK,CAACO,OAAN,CAAc,CAACC,KAAD,EAAQC,MAAR,KAAmB;AAC/B,UAAIC,YAAJ;;AAEA,UAAIf,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBG,QAA3B,EAAqC;AACnCF,QAAAA,YAAY,GAAG,uBAASF,KAAT,EAAgBb,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBI,KAAvC,CAAf;AACD,OAFD,MAEO;AACLH,QAAAA,YAAY,GAAG,yBAAWF,KAAX,EAAkBb,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBI,KAAzC,CAAf;AACD;;AAEDH,MAAAA,YAAY,CAACH,OAAb,CAAqB,CAACO,IAAD,EAAOC,MAAP,KAAkB;AACrCb,QAAAA,SAAS,CAACa,MAAD,CAAT,CAAkBN,MAAlB,IAA4BK,IAA5B;AACD,OAFD;AAGD,KAZD;AAcA,WAAOZ,SAAP;AACD,GAxBkB,CAAnB;AA0BA,SAAOC,gBAAEa,OAAF,CAAUlB,UAAV,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport wrapString from './wrapString';\nimport wrapWord from './wrapWord';\n\n/**\n * @param {Array} unmappedRows\n * @param {number[]} rowHeightIndex\n * @param {Object} config\n * @returns {Array}\n */\nexport default (unmappedRows, rowHeightIndex, config) => {\n const tableWidth = unmappedRows[0].length;\n\n const mappedRows = unmappedRows.map((cells, index0) => {\n const rowHeight = _.times(rowHeightIndex[index0], () => {\n return new Array(tableWidth).fill('');\n });\n\n // rowHeight\n // [{row index within rowSaw; index2}]\n // [{cell index within a virtual row; index1}]\n\n cells.forEach((value, index1) => {\n let chunkedValue;\n\n if (config.columns[index1].wrapWord) {\n chunkedValue = wrapWord(value, config.columns[index1].width);\n } else {\n chunkedValue = wrapString(value, config.columns[index1].width);\n }\n\n chunkedValue.forEach((part, index2) => {\n rowHeight[index2][index1] = part;\n });\n });\n\n return rowHeight;\n });\n\n return _.flatten(mappedRows);\n};\n"],"file":"mapDataUsingRowHeightIndex.js"}
1
+ {"version":3,"sources":["../src/mapDataUsingRowHeightIndex.js"],"names":["unmappedRows","rowHeightIndex","config","tableWidth","length","mappedRows","map","cells","index0","rowHeight","_","times","Array","fill","forEach","value","index1","cellLines","columns","width","wrapWord","cellLine","index2","flatten"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;;oCAMgBA,Y,EAAcC,c,EAAgBC,M,KAAW;AACvD,QAAMC,UAAU,GAAGH,YAAY,CAAC,CAAD,CAAZ,CAAgBI,MAAnC;AAEA,QAAMC,UAAU,GAAGL,YAAY,CAACM,GAAb,CAAiB,CAACC,KAAD,EAAQC,MAAR,KAAmB;AACrD,UAAMC,SAAS,GAAGC,gBAAEC,KAAF,CAAQV,cAAc,CAACO,MAAD,CAAtB,EAAgC,MAAM;AACtD,aAAO,IAAII,KAAJ,CAAUT,UAAV,EAAsBU,IAAtB,CAA2B,EAA3B,CAAP;AACD,KAFiB,CAAlB,CADqD,CAKrD;AACA;AACA;;;AAEAN,IAAAA,KAAK,CAACO,OAAN,CAAc,CAACC,KAAD,EAAQC,MAAR,KAAmB;AAC/B,YAAMC,SAAS,GAAG,uBAASF,KAAT,EAAgBb,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBG,KAAvC,EAA8CjB,MAAM,CAACgB,OAAP,CAAeF,MAAf,EAAuBI,QAArE,CAAlB;AAEAH,MAAAA,SAAS,CAACH,OAAV,CAAkB,CAACO,QAAD,EAAWC,MAAX,KAAsB;AACtCb,QAAAA,SAAS,CAACa,MAAD,CAAT,CAAkBN,MAAlB,IAA4BK,QAA5B;AACD,OAFD;AAGD,KAND;AAQA,WAAOZ,SAAP;AACD,GAlBkB,CAAnB;AAoBA,SAAOC,gBAAEa,OAAF,CAAUlB,UAAV,CAAP;AACD,C","sourcesContent":["import _ from 'lodash';\nimport wrapCell from './wrapCell';\n\n/**\n * @param {Array} unmappedRows\n * @param {number[]} rowHeightIndex\n * @param {Object} config\n * @returns {Array}\n */\nexport default (unmappedRows, rowHeightIndex, config) => {\n const tableWidth = unmappedRows[0].length;\n\n const mappedRows = unmappedRows.map((cells, index0) => {\n const rowHeight = _.times(rowHeightIndex[index0], () => {\n return new Array(tableWidth).fill('');\n });\n\n // rowHeight\n // [{row index within rowSaw; index2}]\n // [{cell index within a virtual row; index1}]\n\n cells.forEach((value, index1) => {\n const cellLines = wrapCell(value, config.columns[index1].width, config.columns[index1].wrapWord);\n\n cellLines.forEach((cellLine, index2) => {\n rowHeight[index2][index1] = cellLine;\n });\n });\n\n return rowHeight;\n });\n\n return _.flatten(mappedRows);\n};\n"],"file":"mapDataUsingRowHeightIndex.js"}
@@ -45,9 +45,7 @@ const validateTableData = rows => {
45
45
 
46
46
  if (cells.length !== columnNumber) {
47
47
  throw new Error('Table must have a consistent number of cells.');
48
- } // @todo Make an exception for newline characters.
49
- // @see https://github.com/gajus/table/issues/9
50
-
48
+ }
51
49
 
52
50
  var _iteratorNormalCompletion2 = true;
53
51
  var _didIteratorError2 = false;
@@ -58,7 +56,7 @@ const validateTableData = rows => {
58
56
  const cell = _step2.value;
59
57
 
60
58
  // eslint-disable-next-line no-control-regex
61
- if (/[\u0001-\u001A]/.test(cell)) {
59
+ if (/[\u0001-\u0009\u000B-\u001A]/.test(cell)) {
62
60
  throw new Error('Table data must not contain control characters.');
63
61
  }
64
62
  }
@@ -34,11 +34,9 @@ export default (rows) => {
34
34
  throw new Error('Table must have a consistent number of cells.');
35
35
  }
36
36
 
37
- // @todo Make an exception for newline characters.
38
- // @see https://github.com/gajus/table/issues/9
39
37
  for (const cell of cells) {
40
38
  // eslint-disable-next-line no-control-regex
41
- if (/[\u0001-\u001A]/.test(cell)) {
39
+ if (/[\u0001-\u0009\u000B-\u001A]/.test(cell)) {
42
40
  throw new Error('Table data must not contain control characters.');
43
41
  }
44
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/validateTableData.js"],"names":["rows","Array","isArray","TypeError","length","Error","columnNumber","cells","cell","test"],"mappings":";;;;;;;AAAA;;;;AAIA;;;;AAIA;;;;0BAIgBA,I,IAAS;AACvB,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAL,EAA0B;AACxB,UAAM,IAAIG,SAAJ,CAAc,8BAAd,CAAN;AACD;;AAED,MAAIH,IAAI,CAACI,MAAL,KAAgB,CAApB,EAAuB;AACrB,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,MAAIL,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAR,KAAmB,CAAvB,EAA0B;AACxB,UAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;AACD;;AAED,QAAMC,YAAY,GAAGN,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAA7B;AAbuB;AAAA;AAAA;;AAAA;AAevB,yBAAoBJ,IAApB,8HAA0B;AAAA,YAAfO,KAAe;;AACxB,UAAI,CAACN,KAAK,CAACC,OAAN,CAAcK,KAAd,CAAL,EAA2B;AACzB,cAAM,IAAIJ,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,UAAII,KAAK,CAACH,MAAN,KAAiBE,YAArB,EAAmC;AACjC,cAAM,IAAID,KAAJ,CAAU,+CAAV,CAAN;AACD,OAPuB,CASxB;AACA;;;AAVwB;AAAA;AAAA;;AAAA;AAWxB,8BAAmBE,KAAnB,mIAA0B;AAAA,gBAAfC,IAAe;;AACxB;AACA,cAAI,kBAAkBC,IAAlB,CAAuBD,IAAvB,CAAJ,EAAkC;AAChC,kBAAM,IAAIH,KAAJ,CAAU,iDAAV,CAAN;AACD;AACF;AAhBuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBzB;AAhCsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCxB,C","sourcesContent":["/**\n * @typedef {string} cell\n */\n\n/**\n * @typedef {cell[]} validateData~column\n */\n\n/**\n * @param {column[]} rows\n * @returns {undefined}\n */\nexport default (rows) => {\n if (!Array.isArray(rows)) {\n throw new TypeError('Table data must be an array.');\n }\n\n if (rows.length === 0) {\n throw new Error('Table must define at least one row.');\n }\n\n if (rows[0].length === 0) {\n throw new Error('Table must define at least one column.');\n }\n\n const columnNumber = rows[0].length;\n\n for (const cells of rows) {\n if (!Array.isArray(cells)) {\n throw new TypeError('Table row data must be an array.');\n }\n\n if (cells.length !== columnNumber) {\n throw new Error('Table must have a consistent number of cells.');\n }\n\n // @todo Make an exception for newline characters.\n // @see https://github.com/gajus/table/issues/9\n for (const cell of cells) {\n // eslint-disable-next-line no-control-regex\n if (/[\\u0001-\\u001A]/.test(cell)) {\n throw new Error('Table data must not contain control characters.');\n }\n }\n }\n};\n"],"file":"validateTableData.js"}
1
+ {"version":3,"sources":["../src/validateTableData.js"],"names":["rows","Array","isArray","TypeError","length","Error","columnNumber","cells","cell","test"],"mappings":";;;;;;;AAAA;;;;AAIA;;;;AAIA;;;;0BAIgBA,I,IAAS;AACvB,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAL,EAA0B;AACxB,UAAM,IAAIG,SAAJ,CAAc,8BAAd,CAAN;AACD;;AAED,MAAIH,IAAI,CAACI,MAAL,KAAgB,CAApB,EAAuB;AACrB,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAED,MAAIL,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAAR,KAAmB,CAAvB,EAA0B;AACxB,UAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;AACD;;AAED,QAAMC,YAAY,GAAGN,IAAI,CAAC,CAAD,CAAJ,CAAQI,MAA7B;AAbuB;AAAA;AAAA;;AAAA;AAevB,yBAAoBJ,IAApB,8HAA0B;AAAA,YAAfO,KAAe;;AACxB,UAAI,CAACN,KAAK,CAACC,OAAN,CAAcK,KAAd,CAAL,EAA2B;AACzB,cAAM,IAAIJ,SAAJ,CAAc,kCAAd,CAAN;AACD;;AAED,UAAII,KAAK,CAACH,MAAN,KAAiBE,YAArB,EAAmC;AACjC,cAAM,IAAID,KAAJ,CAAU,+CAAV,CAAN;AACD;;AAPuB;AAAA;AAAA;;AAAA;AASxB,8BAAmBE,KAAnB,mIAA0B;AAAA,gBAAfC,IAAe;;AACxB;AACA,cAAI,+BAA+BC,IAA/B,CAAoCD,IAApC,CAAJ,EAA+C;AAC7C,kBAAM,IAAIH,KAAJ,CAAU,iDAAV,CAAN;AACD;AACF;AAduB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAezB;AA9BsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BxB,C","sourcesContent":["/**\n * @typedef {string} cell\n */\n\n/**\n * @typedef {cell[]} validateData~column\n */\n\n/**\n * @param {column[]} rows\n * @returns {undefined}\n */\nexport default (rows) => {\n if (!Array.isArray(rows)) {\n throw new TypeError('Table data must be an array.');\n }\n\n if (rows.length === 0) {\n throw new Error('Table must define at least one row.');\n }\n\n if (rows[0].length === 0) {\n throw new Error('Table must define at least one column.');\n }\n\n const columnNumber = rows[0].length;\n\n for (const cells of rows) {\n if (!Array.isArray(cells)) {\n throw new TypeError('Table row data must be an array.');\n }\n\n if (cells.length !== columnNumber) {\n throw new Error('Table must have a consistent number of cells.');\n }\n\n for (const cell of cells) {\n // eslint-disable-next-line no-control-regex\n if (/[\\u0001-\\u0009\\u000B-\\u001A]/.test(cell)) {\n throw new Error('Table data must not contain control characters.');\n }\n }\n }\n};\n"],"file":"validateTableData.js"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _wrapString = _interopRequireDefault(require("./wrapString"));
9
+
10
+ var _wrapWord = _interopRequireDefault(require("./wrapWord"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /**
15
+ * Wrap a single cell value into a list of lines
16
+ *
17
+ * Always wraps on newlines, for the remainder uses either word or string wrapping
18
+ * depending on user configuration.
19
+ *
20
+ * @param {string} cellValue
21
+ * @param {number} columnWidth
22
+ * @param {boolean} useWrapWord
23
+ * @returns {Array}
24
+ */
25
+ const wrapCell = (cellValue, columnWidth, useWrapWord) => {
26
+ // First split on literal newlines
27
+ const cellLines = cellValue.split('\n'); // Then iterate over the list and word-wrap every remaining line if necessary.
28
+
29
+ for (let lineNr = 0; lineNr < cellLines.length;) {
30
+ let lineChunks;
31
+
32
+ if (useWrapWord) {
33
+ lineChunks = (0, _wrapWord.default)(cellLines[lineNr], columnWidth);
34
+ } else {
35
+ lineChunks = (0, _wrapString.default)(cellLines[lineNr], columnWidth);
36
+ } // Replace our original array element with whatever the wrapping returned
37
+
38
+
39
+ cellLines.splice(lineNr, 1, ...lineChunks);
40
+ lineNr += lineChunks.length;
41
+ }
42
+
43
+ return cellLines;
44
+ };
45
+
46
+ var _default = wrapCell;
47
+ exports.default = _default;
48
+ //# sourceMappingURL=wrapCell.js.map
@@ -0,0 +1,35 @@
1
+ import wrapString from './wrapString';
2
+ import wrapWord from './wrapWord';
3
+
4
+ /**
5
+ * Wrap a single cell value into a list of lines
6
+ *
7
+ * Always wraps on newlines, for the remainder uses either word or string wrapping
8
+ * depending on user configuration.
9
+ *
10
+ * @param {string} cellValue
11
+ * @param {number} columnWidth
12
+ * @param {boolean} useWrapWord
13
+ * @returns {Array}
14
+ */
15
+ export default (cellValue, columnWidth, useWrapWord) => {
16
+ // First split on literal newlines
17
+ const cellLines = cellValue.split('\n');
18
+
19
+ // Then iterate over the list and word-wrap every remaining line if necessary.
20
+ for (let lineNr = 0; lineNr < cellLines.length;) {
21
+ let lineChunks;
22
+
23
+ if (useWrapWord) {
24
+ lineChunks = wrapWord(cellLines[lineNr], columnWidth);
25
+ } else {
26
+ lineChunks = wrapString(cellLines[lineNr], columnWidth);
27
+ }
28
+
29
+ // Replace our original array element with whatever the wrapping returned
30
+ cellLines.splice(lineNr, 1, ...lineChunks);
31
+ lineNr += lineChunks.length;
32
+ }
33
+
34
+ return cellLines;
35
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/wrapCell.js"],"names":["cellValue","columnWidth","useWrapWord","cellLines","split","lineNr","length","lineChunks","splice"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;;;;;;;;;;;kBAWgBA,S,EAAWC,W,EAAaC,W,KAAgB;AACtD;AACA,QAAMC,SAAS,GAAGH,SAAS,CAACI,KAAV,CAAgB,IAAhB,CAAlB,CAFsD,CAItD;;AACA,OAAK,IAAIC,MAAM,GAAG,CAAlB,EAAqBA,MAAM,GAAGF,SAAS,CAACG,MAAxC,GAAiD;AAC/C,QAAIC,UAAJ;;AAEA,QAAIL,WAAJ,EAAiB;AACfK,MAAAA,UAAU,GAAG,uBAASJ,SAAS,CAACE,MAAD,CAAlB,EAA4BJ,WAA5B,CAAb;AACD,KAFD,MAEO;AACLM,MAAAA,UAAU,GAAG,yBAAWJ,SAAS,CAACE,MAAD,CAApB,EAA8BJ,WAA9B,CAAb;AACD,KAP8C,CAS/C;;;AACAE,IAAAA,SAAS,CAACK,MAAV,CAAiBH,MAAjB,EAAyB,CAAzB,EAA4B,GAAGE,UAA/B;AACAF,IAAAA,MAAM,IAAIE,UAAU,CAACD,MAArB;AACD;;AAED,SAAOH,SAAP;AACD,C","sourcesContent":["import wrapString from './wrapString';\nimport wrapWord from './wrapWord';\n\n/**\n * Wrap a single cell value into a list of lines\n *\n * Always wraps on newlines, for the remainder uses either word or string wrapping\n * depending on user configuration.\n *\n * @param {string} cellValue\n * @param {number} columnWidth\n * @param {boolean} useWrapWord\n * @returns {Array}\n */\nexport default (cellValue, columnWidth, useWrapWord) => {\n // First split on literal newlines\n const cellLines = cellValue.split('\\n');\n\n // Then iterate over the list and word-wrap every remaining line if necessary.\n for (let lineNr = 0; lineNr < cellLines.length;) {\n let lineChunks;\n\n if (useWrapWord) {\n lineChunks = wrapWord(cellLines[lineNr], columnWidth);\n } else {\n lineChunks = wrapString(cellLines[lineNr], columnWidth);\n }\n\n // Replace our original array element with whatever the wrapping returned\n cellLines.splice(lineNr, 1, ...lineChunks);\n lineNr += lineChunks.length;\n }\n\n return cellLines;\n};\n"],"file":"wrapCell.js"}
package/package.json CHANGED
@@ -5,18 +5,18 @@
5
5
  "url": "http://gajus.com"
6
6
  },
7
7
  "dependencies": {
8
- "ajv": "^6.5.3",
9
- "lodash": "^4.17.10",
10
- "slice-ansi": "1.0.0",
8
+ "ajv": "^6.6.1",
9
+ "lodash": "^4.17.11",
10
+ "slice-ansi": "^2.0.0",
11
11
  "string-width": "^2.1.1"
12
12
  },
13
13
  "description": "Formats data into a string table.",
14
14
  "devDependencies": {
15
- "@babel/cli": "^7.1.2",
16
- "@babel/core": "^7.1.2",
15
+ "@babel/cli": "^7.1.5",
16
+ "@babel/core": "^7.1.6",
17
17
  "@babel/node": "^7.0.0",
18
- "@babel/plugin-transform-flow-strip-types": "^7.0.0",
19
- "@babel/preset-env": "^7.1.0",
18
+ "@babel/plugin-transform-flow-strip-types": "^7.1.6",
19
+ "@babel/preset-env": "^7.1.6",
20
20
  "@babel/register": "^7.0.0",
21
21
  "ajv-cli": "^3.0.0",
22
22
  "ajv-keywords": "^3.2.0",
@@ -25,16 +25,16 @@
25
25
  "chai": "^4.2.0",
26
26
  "chalk": "^2.4.1",
27
27
  "coveralls": "^3.0.2",
28
- "eslint": "^5.6.1",
28
+ "eslint": "^5.9.0",
29
29
  "eslint-config-canonical": "^13.0.0",
30
- "flow-bin": "^0.81.0",
30
+ "flow-bin": "^0.87.0",
31
31
  "flow-copy-source": "^2.0.2",
32
- "gitdown": "^2.5.4",
33
- "husky": "^1.0.1",
32
+ "gitdown": "^2.5.5",
33
+ "husky": "^1.2.0",
34
34
  "mocha": "^5.2.0",
35
35
  "nyc": "^13.1.0",
36
- "semantic-release": "^15.9.16",
37
- "sinon": "^6.3.4"
36
+ "semantic-release": "^15.12.3",
37
+ "sinon": "^7.1.1"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=6.0.0"
@@ -79,5 +79,5 @@
79
79
  "lint": "npm run build && eslint ./src ./test && flow",
80
80
  "test": "mocha --require @babel/register"
81
81
  },
82
- "version": "5.1.0"
82
+ "version": "5.2.2"
83
83
  }