<commit_before>"use strict";

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

module.exports = {
  resolveDirectory: resolveDirectory,
  humanVolume: humanVolume,
  fatalError: fatalError,
  sum: sum,
  cliTimeAgo: cliTimeAgo,
};


function resolveDirectory(dir) {
  var fullPath = path.resolve(dir || process.cwd());
  if (!(fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory())) {
    fatalError(fullPath + ' is not a directory!');
  }
  return fullPath;
}

function humanVolume(volume) {
  var sizes = ['B', 'K', 'M', 'G', 'T'];
  while (sizes.length > 1 && volume > 1024) {
    volume /= 1024;
    sizes.shift();
  };
  return volume.toFixed(3) + sizes[0];
}

function fatalError(message) {
  console.log(clc.red(message));
  process.exit();
}

function sum(a, b) {
  return a + b;
}


////////////////////////////////////////////////////////////////////////////////
//TODO: All of this is pasted straight from nsyrc/lib/commands/linksDataUtils.js
//Move to own package or just lib:
function cliTimeAgo(unixTimeStamp) {
  return new ProcessedString(unixTimeStamp ? moment(unixTimeStamp).fromNow() : "Never", timeAgoColorFunction(unixTimeStamp));
}
function ProcessedString(str, funcArray) {
  this.str = str;
  this.length = this.str.length;
  this.funcArray = (funcArray instanceof Array) ? funcArray : [funcArray];
}
ProcessedString.prototype.toString = function() {
  return this.funcArray.filter(Boolean).reduce(function(prev, curr) { return curr(prev); }, this.str);
}
function timeAgoColorFunction(unixTimeStamp) {
  var updateStatus = getUpdateStatus(unixTimeStamp);
  if (updateStatus == LinkUpdateStatus.OLD) return clc.red;
  if (updateStatus == LinkUpdateStatus.SEMI) return clc.yellow;
  if (updateStatus == LinkUpdateStatus.NEW) return clc.white;
}
function getUpdateStatus(unixTimeStamp) {
  var secondsAgo = moment().diff(moment(unixTimeStamp || 0)) / 1000;
  if (secondsAgo > 60*60*24*7) { //TODO: this time period (week) should be configurable. //From outside the package!
    return LinkUpdateStatus.OLD;
  } else if (secondsAgo > 60*60*24) { //TODO: this time period (day) should be configurable. //From outside the package!
    return LinkUpdateStatus.SEMI;
  }
  return LinkUpdateStatus.NEW;
}
var LinkUpdateStatus = {
  NEW: 'new',
  SEMI: 'semi',
  OLD: 'old'
}

////////////////////////////////////////////////////////////////////////////////<commit_msg>removed duplicate require<commit_after>"use strict";

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

module.exports = {
  resolveDirectory: resolveDirectory,
  humanVolume: humanVolume,
  fatalError: fatalError,
  sum: sum,
  cliTimeAgo: cliTimeAgo,
};


function resolveDirectory(dir) {
  var fullPath = path.resolve(dir || process.cwd());
  if (!(fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory())) {
    fatalError(fullPath + ' is not a directory!');
  }
  return fullPath;
}

function humanVolume(volume) {
  var sizes = ['B', 'K', 'M', 'G', 'T'];
  while (sizes.length > 1 && volume > 1024) {
    volume /= 1024;
    sizes.shift();
  };
  return volume.toFixed(3) + sizes[0];
}

function fatalError(message) {
  console.log(clc.red(message));
  process.exit();
}

function sum(a, b) {
  return a + b;
}


////////////////////////////////////////////////////////////////////////////////
//TODO: All of this is pasted straight from nsyrc/lib/commands/linksDataUtils.js
//Move to own package or just lib:
function cliTimeAgo(unixTimeStamp) {
  return new ProcessedString(unixTimeStamp ? moment(unixTimeStamp).fromNow() : "Never", timeAgoColorFunction(unixTimeStamp));
}
function ProcessedString(str, funcArray) {
  this.str = str;
  this.length = this.str.length;
  this.funcArray = (funcArray instanceof Array) ? funcArray : [funcArray];
}
ProcessedString.prototype.toString = function() {
  return this.funcArray.filter(Boolean).reduce(function(prev, curr) { return curr(prev); }, this.str);
}
function timeAgoColorFunction(unixTimeStamp) {
  var updateStatus = getUpdateStatus(unixTimeStamp);
  if (updateStatus == LinkUpdateStatus.OLD) return clc.red;
  if (updateStatus == LinkUpdateStatus.SEMI) return clc.yellow;
  if (updateStatus == LinkUpdateStatus.NEW) return clc.white;
}
function getUpdateStatus(unixTimeStamp) {
  var secondsAgo = moment().diff(moment(unixTimeStamp || 0)) / 1000;
  if (secondsAgo > 60*60*24*7) { //TODO: this time period (week) should be configurable. //From outside the package!
    return LinkUpdateStatus.OLD;
  } else if (secondsAgo > 60*60*24) { //TODO: this time period (day) should be configurable. //From outside the package!
    return LinkUpdateStatus.SEMI;
  }
  return LinkUpdateStatus.NEW;
}
var LinkUpdateStatus = {
  NEW: 'new',
  SEMI: 'semi',
  OLD: 'old'
}

////////////////////////////////////////////////////////////////////////////////
{'fraction_non_alphanumeric': 0.1977446637132501, 'fraction_numerical': 0.011679420056383408, 'mean_word_length': 3.3531989482909728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6159890', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1561, 'n_words': 381}