<commit_before>
/**

  cli-utils

  Helper functions for cli interface.

**/


//
//  Dependencies
//

var chalk = require("chalk"),
    fs = require("fs");


//
//  Exports
//

var utils = module.exports = {};



/**

  Right appends spaces to a string

  @param {String} str Base string
  @param {Number} len Desired length
  @returns {String} The padded string

**/

utils.pad = function(str, len) {
  while (str.length < len) str += " ";
  return str;
}



/**

  Sorts and outputs strings in a grid format.

  @param {Array} grid Array of lines, where each line has two cells (e.g. ["A", "B"])
  @param {Number} options.len Length of each column
  @param {String} [options.title] Title to display above the grid
  @param {Array} [options.headers] Array of strings containing column headers

**/

utils.showGrid = function(grid, options) {

  var str;

  options = options || {},

  grid.sort(function(a, b) {
    return (a[0] < b[0]) ? -1 : (a[0] > b[0]) ? 1 : 0;
  });

  console.log("");

  if (options.title) {
    console.log(" " + chalk.cyan(options.title));
    console.log("");
  }

  if (options.headers) {
    str = "    ";
    for (var j = 0, m = options.headers.length; j < m; j++)
      str += utils.pad(options.headers[j], options.len);
    console.log(chalk.yellow(str));
  }

  for (var i = 0, n = grid.length; i < n; i++) {
    str = "    ";
    for (var j = 0, m = grid[i].length; j < m; j++)<commit_msg>cli-utils: makes sorting optional<commit_after>
/**

  cli-utils

  Helper functions for cli interface.

**/


//
//  Dependencies
//

var chalk = require("chalk"),
    fs = require("fs");


//
//  Exports
//

var utils = module.exports = {};



/**

  Right appends spaces to a string

  @param {String} str Base string
  @param {Number} len Desired length
  @returns {String} The padded string

**/

utils.pad = function(str, len) {
  while (str.length < len) str += " ";
  return str;
}



/**

  Sorts and outputs strings in a grid format.

  @param {Array} grid Array of lines, where each line has two cells (e.g. ["A", "B"])
  @param {Number} options.len Length of each column
  @param {String} [options.title] Title to display above the grid
  @param {Array} [options.headers] Array of strings containing column headers

**/

utils.showGrid = function(grid, options) {

  var str;

  options = options || {};
  if ("undefined" === typeof options.sort) options.sort = true;

  if (options.sort)
    grid.sort(function(a, b) {
      return (a[0] < b[0]) ? -1 : (a[0] > b[0]) ? 1 : 0;
    });

  console.log("");

  if (options.title) {
    console.log(" " + chalk.cyan(options.title));
    console.log("");
  }

  if (options.headers) {
    str = "    ";
    for (var j = 0, m = options.headers.length; j < m; j++)
      str += utils.pad(options.headers[j], options.len);
    console.log(chalk.yellow(str));
  }

  for (var i = 0, n = grid.length; i < n; i++) {
    str = "    ";
    for (var j = 0, m = grid[i].length; j < m; j++)
{'fraction_non_alphanumeric': 0.17353139770425388, 'fraction_numerical': 0.00675219446320054, 'mean_word_length': 2.70375, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '4691308', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1030, 'n_words': 316}