alignTableData.js.flow 503 B

123456789101112131415161718192021
  1. import stringWidth from 'string-width';
  2. import alignString from './alignString';
  3. /**
  4. * @param {table~row[]} rows
  5. * @param {Object} config
  6. * @returns {table~row[]}
  7. */
  8. export default (rows, config) => {
  9. return rows.map((cells) => {
  10. return cells.map((value, index1) => {
  11. const column = config.columns[index1];
  12. if (stringWidth(value) === column.width) {
  13. return value;
  14. } else {
  15. return alignString(value, column.width, column.alignment);
  16. }
  17. });
  18. });
  19. };