<commit_before>'use strict';

var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var autils = require('./AUtils');

var StringWriter = function (config, outputText, ext) {

  if (typeof outputText !== "string") {
    throw new Error("The outputText provided is not a 'string' value but is a typeof " + (typeof outputText));
  }

  this.config = config;
  this.ext = ext || "txt";
  this.outputText = outputText;
};

var lineEndingRegex = new RegExp("\r?\n", "g"); //eslint-disable-line no-control-regex
function normalizeLineEndings(lineEnding, value) {
  if (autils.isBinaryFile(value)) {
    return value;
  }
  return value.replace(lineEndingRegex, lineEnding);
}

StringWriter.prototype.getFileExtension = function () {
  return this.ext;
};

StringWriter.prototype.write = function (filePath) {

  var dir = path.dirname(path.normalize(filePath));
  if (!fs.existsSync(dir)) {
    mkdirp.sync(dir);
  }

  if (this.config.normalizeLineEndingsTo !== false && this.config.normalizeLineEndingsTo !== undefined) {
    this.outputText = normalizeLineEndings(this.config.normalizeLineEndingsTo, this.outputText);
  }

  if (this.config.appendEOL) {

    var CRLF = "\r\n";
    var LF = "\n";

    var endsWithCRLF = this.outputText && this.outputText.length >= 2 &&
      this.outputText[this.outputText.length - 2] === CRLF[0] &&
      this.outputText[this.outputText.length - 1] === CRLF[1];
    var endsWithLF = this.outputText && this.outputText.length >= 1 &&
      this.outputText[this.outputText.length - 1] === LF;

    if (!endsWithCRLF && !endsWithLF) {
      console.log("ADDING EOL - " + JSON.stringify(this.config.EOL));
      this.outputText += this.config.EOL;
    } else if (endsWithCRLF && this.config.EOL === LF) {
      console.log("NOT ADDING EOL - " + JSON.stringify(this.config.EOL) + ' because ' + JSON.stringify(LF) + ' already there.');
    } else if (endsWithLF && this.config.EOL === CRLF) {
      console.log("NOT ADDING EOL - " + JSON.stringify(this.config.EOL) + ' because ' + JSON.stringify(CRLF) + ' already there.');
    }

  }
  fs.writeFileSync(filePath, this.outputText);
};

module.exports = StringWriter;<commit_msg>remove console log statements when not changing content<commit_after>'use strict';

var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var autils = require('./AUtils');

var StringWriter = function (config, outputText, ext) {

  if (typeof outputText !== "string") {
    throw new Error("The outputText provided is not a 'string' value but is a typeof " + (typeof outputText));
  }

  this.config = config;
  this.ext = ext || "txt";
  this.outputText = outputText;
};

var lineEndingRegex = new RegExp("\r?\n", "g"); //eslint-disable-line no-control-regex
function normalizeLineEndings(lineEnding, value) {
  if (autils.isBinaryFile(value)) {
    return value;
  }
  return value.replace(lineEndingRegex, lineEnding);
}

StringWriter.prototype.getFileExtension = function () {
  return this.ext;
};

StringWriter.prototype.write = function (filePath) {

  var dir = path.dirname(path.normalize(filePath));
  if (!fs.existsSync(dir)) {
    mkdirp.sync(dir);
  }

  if (this.config.normalizeLineEndingsTo !== false && this.config.normalizeLineEndingsTo !== undefined) {
    this.outputText = normalizeLineEndings(this.config.normalizeLineEndingsTo, this.outputText);
  }

  if (this.config.appendEOL) {

    var CRLF = "\r\n";
    var LF = "\n";

    var endsWithCRLF = this.outputText && this.outputText.length >= 2 &&
      this.outputText[this.outputText.length - 2] === CRLF[0] &&
      this.outputText[this.outputText.length - 1] === CRLF[1];
    var endsWithLF = this.outputText && this.outputText.length >= 1 &&
      this.outputText[this.outputText.length - 1] === LF;

    if (!endsWithCRLF && !endsWithLF) {
      console.log("ADDING EOL - " + JSON.stringify(this.config.EOL));
      this.outputText += this.config.EOL;
    }

  }
  fs.writeFileSync(filePath, this.outputText);
};

module.exports = StringWriter;
{'fraction_non_alphanumeric': 0.15544554455445544, 'fraction_numerical': 0.0034653465346534654, 'mean_word_length': 3.799287410926366, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '875432', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1315, 'n_words': 280}