<commit_before>'use strict';

const chalk = require('chalk');
const assert = require('assert');
const csvString = require('csv-string');
const tableLib = require('table');
const table = tableLib.table;
const markdownTable = require('markdown-table');

/**
 * @type {FORMAT}
 * @readonly
 * @enum {string}
 */
const FORMAT = {
  CSV: 'csv',
  JSON: 'json',
  MD: 'md',
  TABLE: 'table',
  TEXT: 'text',
  TSV: 'tsv',
};
const FORMATS = Object.values(FORMAT);

/**
 * @typedef ColumnDefinition
 * @property {String} label label used for the table header
 * @property {String} attribute name of the attribute which should be shown
 * @property {function} format optional function for formatting the value
 * @property {Number} width fixed with column
 * @property {String} alignment either left, right or center
 * @property {Boolean} wrapWord flag for wrapping long words when column width reached
 */

/**
 * @param {Array<Object>} items
 * @param {Array<ColumnDefinition} columns
 * @return {Array<Array<String>>}
 */
function compileTableData(items, columns) {
  assert(Array.isArray(items), 'expected data to be an array');
  assert(Array.isArray(columns), 'expected columns to be an array');

  return items.map(item => {
    // format the value of the column according to the column definition
    // or formatting function
    let row = columns.map(columnDefinition => {
      const value = item[columnDefinition.attribute];
      if (typeof columnDefinition.format === 'function') {
        return columnDefinition.format(value, item);
      }
      return value;
    });
    // show archived items in grey
    if (item.archived) {
      row = row.map(v => chalk.grey(v));
    }
    // colorize the whole row when it’s actively tracked or archived
    if (item.tracking) {
      row = row.map(v => chalk.yellow(v));
    }
    if (item.locked) {
      row = row.map(v => chalk.grey(v));
    }
    return row;
  });
}

/**
 * @param {Array<Object>} items
 * @param {Array<ColumnDefinition} columns
 * @return {Array<Array<String>>}
 */
function getTableFooterColumns(items, columns) {
  assert(Array.isArray(items), 'expected items to be an array');
  assert(Array.isArray(columns), 'expected columns to be an array');

  return columns.map(columnDefinition => {
    let columnSum;
    if (columnDefinition.reducer) {
      columnSum = items.reduce(columnDefinition.reducer, null);
    }
    if (columnSum && columnDefinition.format) {
      return columnDefinition.format(columnSum);
    }<commit_msg>fix(mite-list): no colored undefined revenue anymore<commit_after>'use strict';

const chalk = require('chalk');
const assert = require('assert');
const csvString = require('csv-string');
const tableLib = require('table');
const table = tableLib.table;
const markdownTable = require('markdown-table');

/**
 * @type {FORMAT}
 * @readonly
 * @enum {string}
 */
const FORMAT = {
  CSV: 'csv',
  JSON: 'json',
  MD: 'md',
  TABLE: 'table',
  TEXT: 'text',
  TSV: 'tsv',
};
const FORMATS = Object.values(FORMAT);

/**
 * @typedef ColumnDefinition
 * @property {String} label label used for the table header
 * @property {String} attribute name of the attribute which should be shown
 * @property {function} format optional function for formatting the value
 * @property {Number} width fixed with column
 * @property {String} alignment either left, right or center
 * @property {Boolean} wrapWord flag for wrapping long words when column width reached
 */

/**
 * @param {Array<Object>} items
 * @param {Array<ColumnDefinition} columns
 * @return {Array<Array<String>>}
 */
function compileTableData(items, columns) {
  assert(Array.isArray(items), 'expected data to be an array');
  assert(Array.isArray(columns), 'expected columns to be an array');

  return items.map(item => {
    // format the value of the column according to the column definition
    // or formatting function
    let row = columns.map(columnDefinition => {
      const value = item[columnDefinition.attribute];
      if (typeof columnDefinition.format === 'function') {
        return columnDefinition.format(value, item);
      }
      return value;
    });
    // show archived items in grey
    if (item.archived) {
      row = row.map(v => v ? chalk.grey(v) : v);
    }
    // colorize the whole row when it’s actively tracked or archived
    if (item.tracking) {
      row = row.map(v => v ? chalk.yellow(v) : v);
    }
    if (item.locked) {
      row = row.map(v => v ? chalk.grey(v) : v);
    }
    return row;
  });
}

/**
 * @param {Array<Object>} items
 * @param {Array<ColumnDefinition} columns
 * @return {Array<Array<String>>}
 */
function getTableFooterColumns(items, columns) {
  assert(Array.isArray(items), 'expected items to be an array');
  assert(Array.isArray(columns), 'expected columns to be an array');

  return columns.map(columnDefinition => {
    let columnSum;
    if (columnDefinition.reducer) {
      columnSum = items.reduce(columnDefinition.reducer, null);
    }
    if (columnSum && columnDefinition.format) {
      return columnDefinition.format(columnSum);
    }
{'fraction_non_alphanumeric': 0.13438423645320197, 'fraction_numerical': 0.0, 'mean_word_length': 3.721860465116279, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7556931', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1469, 'n_words': 463}