Sha256: b761842b08c6b07c8bbd4d47704babc373ffb4929f2a8be1415ebd9c57d91a15

Contents?: true

Size: 1.45 KB

Versions: 43

Compression:

Stored size: 1.45 KB

Contents

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _wrapString = require('./wrapString');

var _wrapString2 = _interopRequireDefault(_wrapString);

var _wrapWord = require('./wrapWord');

var _wrapWord2 = _interopRequireDefault(_wrapWord);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * @param {Array} unmappedRows
 * @param {number[]} rowHeightIndex
 * @param {Object} config
 * @returns {Array}
 */
exports.default = (unmappedRows, rowHeightIndex, config) => {
  const tableWidth = unmappedRows[0].length;

  const mappedRows = unmappedRows.map((cells, index0) => {
    const rowHeight = _lodash2.default.times(rowHeightIndex[index0], () => {
      return Array(tableWidth).fill('');
    });

    // rowHeight
    //     [{row index within rowSaw; index2}]
    //     [{cell index within a virtual row; index1}]

    cells.forEach((value, index1) => {
      let chunkedValue;

      if (config.columns[index1].wrapWord) {
        chunkedValue = (0, _wrapWord2.default)(value, config.columns[index1].width);
      } else {
        chunkedValue = (0, _wrapString2.default)(value, config.columns[index1].width);
      }

      chunkedValue.forEach((part, index2) => {
        rowHeight[index2][index1] = part;
      });
    });

    return rowHeight;
  });

  return _lodash2.default.flatten(mappedRows);
};

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.21.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.20.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.19.1 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.19.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.18.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.17.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.16.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.15.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.14.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.13.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.12.2 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.12.1 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.12.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.11.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.10.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.9.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.8.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.7.0 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js
govuk_publishing_components-17.6.1 node_modules/standard/node_modules/table/dist/mapDataUsingRowHeightIndex.js