<commit_before>"use strict";

var clc = require('cli-color');
var fs = require('fs');
var rek = require('rekuire');
var path = require('path');
var moment = require('moment');

var getCwd = rek('getCwd');


module.exports = {
    format: format,
    varify: varify,
    stringify: stringify,
    stringifyList: stringifyList,
    tablifyList: tablifyList
};


function format(link) {
    link.source = formatFolder(link.source);
    link.target = formatFolder(link.target);
    return varify(link);
}

function varify(link) {
    return varifyFolder(link.source) && varifyFolder(link.target) && link;
}

function stringify(link) {
    return printedData(link).join(' ');
}

function stringifyList(list) {
    var table = list.map(printedData);
    var maxLengths = [];
    for (var key in table) {
      for (var i in table[key]) {
        maxLengths[i] = Math.max(maxLengths[i] || 0, realLength(table[key][i]));
      }
    }
    // Another way to calculate maxLength; more fun, but heckish as hell. This is here as an example for the curious reader:
    // var maxLengths = table[0].map(function(v,columnIndex) { return table.reduce(function(max, row) { return Math.max(max, realLength(row[columnIndex])); }, 0); });
    return table.map(function(row) {
      return row.map(function(val,i) {
        return pad(val,maxLengths[i]);
      }).join(' ');
    }).join('\n');
}

function tablifyList(list) {
  var table = "<table>";

  list.map(function(v, i) {
    table += "<tr>";
    table += "<td>" + v.id + "</td>";
    table += "<td class='folder " + foldersStatus(v.source) + "'>" + v.source + "</td>";
    table += "<td class='folder " + foldersStatus(v.target) + "'>" + v.target + "</td>";
    table += "<td class='timeago " + getTimeAgoStyle(v.lastSynced) + "'>(" + getTimeAgoString(v.lastSynced) + ")</td>";
    table += "<td><span class='run' id='" + v.id + "'>Run</span><span class='delete' id='" + v.id + "'>Delete</span></td>";
    table += "</tr>";
  });

  table += "</table>";

  return table;
}

////////////////////////////////////////////////////////////////////////////////

function printedData(link) {
  return [link.id+":", cliColorFolder(link.source), "-->", cliColorFolder(link.target), lastUpdated(link)];
}

function realLength(str) {
  return str.replace(/.\[[0-9;]+m/g,'').length; //This removes color codes;
}

function pad(str, len) {
  for (var cur = realLength(str); cur < len; cur++) {
    str += '.';
  }
  return str;
}

function lastUpdated(link) {
    var timeAgo = ["(",getTimeAgoString(link.lastSynced),")"].join("");
    var style = getTimeAgoStyle(link.lastSynced);

    if (style == 'old') {
      return clc.red(timeAgo);
    } else if (style == 'semi') {
      return clc.yellow(timeAgo);
    } else if (style == 'new') {
      return timeAgo;
    }
}

function getTimeAgoString(unixTimeStamp) {<commit_msg>small function arg refactor<commit_after>"use strict";

var clc = require('cli-color');
var fs = require('fs');
var rek = require('rekuire');
var path = require('path');
var moment = require('moment');

var getCwd = rek('getCwd');


module.exports = {
    format: format,
    varify: varify,
    stringify: stringify,
    stringifyList: stringifyList,
    tablifyList: tablifyList
};


function format(link) {
    link.source = formatFolder(link.source);
    link.target = formatFolder(link.target);
    return varify(link);
}

function varify(link) {
    return varifyFolder(link.source) && varifyFolder(link.target) && link;
}

function stringify(link) {
    return printedData(link).join(' ');
}

function stringifyList(list) {
    var table = list.map(printedData);
    var maxLengths = [];
    for (var key in table) {
      for (var i in table[key]) {
        maxLengths[i] = Math.max(maxLengths[i] || 0, realLength(table[key][i]));
      }
    }
    // Another way to calculate maxLength; more fun, but heckish as hell. This is here as an example for the curious reader:
    // var maxLengths = table[0].map(function(v,columnIndex) { return table.reduce(function(max, row) { return Math.max(max, realLength(row[columnIndex])); }, 0); });
    return table.map(function(row) {
      return row.map(function(val,i) {
        return pad(val,maxLengths[i]);
      }).join(' ');
    }).join('\n');
}

function tablifyList(list) {
  var table = "<table>";

  list.map(function(v, i) {
    table += "<tr>";
    table += "<td>" + v.id + "</td>";
    table += "<td class='folder " + foldersStatus(v.source) + "'>" + v.source + "</td>";
    table += "<td class='folder " + foldersStatus(v.target) + "'>" + v.target + "</td>";
    table += "<td class='timeago " + getTimeAgoStyle(v.lastSynced) + "'>(" + getTimeAgoString(v.lastSynced) + ")</td>";
    table += "<td><span class='run' id='" + v.id + "'>Run</span><span class='delete' id='" + v.id + "'>Delete</span></td>";
    table += "</tr>";
  });

  table += "</table>";

  return table;
}

////////////////////////////////////////////////////////////////////////////////

function printedData(link) {
  return [link.id+":", cliColorFolder(link.source), "-->", cliColorFolder(link.target), lastUpdated(link.lastSynced)];
}

function realLength(str) {
  return str.replace(/.\[[0-9;]+m/g,'').length; //This removes color codes;
}

function pad(str, len) {
  for (var cur = realLength(str); cur < len; cur++) {
    str += '.';
  }
  return str;
}

function lastUpdated(unixTimeStamp) {
    var timeAgo = ["(",getTimeAgoString(unixTimeStamp),")"].join("");
    var style = getTimeAgoStyle(unixTimeStamp);

    if (style == 'old') {
      return clc.red(timeAgo);
    } else if (style == 'semi') {
      return clc.yellow(timeAgo);
    } else if (style == 'new') {
      return timeAgo;
    }
}

function getTimeAgoString(unixTimeStamp) {
{'fraction_non_alphanumeric': 0.2158060013956734, 'fraction_numerical': 0.0017445917655268667, 'mean_word_length': 3.175528040786599, 'pattern_counts': {'":': 2, '<': 41, '<?xml version=': 0, '>': 41, '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': '2465046', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1926, 'n_words': 425}