<commit_before>randomFromArr = function(arr) {
  return arr[Math.floor(Math.random() * arr.length)];
}

extend = function(from, to) {
  if (from == null || typeof from != "object") return from;
  if (from.constructor != Object && from.constructor != Array) return from;
  if (from.constructor == Date || from.constructor == RegExp || from.constructor == Function ||
    from.constructor == String || from.constructor == Number || from.constructor == Boolean)
    return new from.constructor(from);

  to = to || new from.constructor();

  for (var name in from) {
    to[name] = typeof to[name] == "undefined" ? extend(from[name], null) : to[name];
  }

  return to;
}

isEmpty = function(obj) {
  return Object.keys(obj).length === 0;
}

escapeStr = function(str) {
  if (typeof str === "string") {
    return str ? str.replace(/\"/g, '\\\"') : str;
  }
}

cleanEmbed = function(data) {
  var arr = [];
  arr.push(
    "_id",
    "slug",
    "createdAt",
    "lastEdited",
    "version",
    "build",
    "heading",
    "qualifier",
    "source",
    "md5",
    "date_format",
    "time_format",
    "print",
    "img",
    "prefix",
    "series",
    "annotations",
    "range",
    "public",
    "users",
    "tags"
  );
  var chartObj = deleteProp(data, arr);
  var newData = csvFormat(data);
  chartObj.data = newData;
  return deleteNullProps(chartObj);
}

embed = function(obj) {
  var data = {
    "version": obj.version,
    "id": obj._id,
    "heading": escapeStr(obj.heading),
    "qualifier": escapeStr(obj.qualifier),
    "source": escapeStr(obj.source),
    "tags": escapeStr(obj.tags)
  };
  data["chart"] = cleanEmbed(obj);
  return data;
}

deleteNullProps = function(obj) {
  for (var i in obj) {
    if ((obj[i] === null) || (obj[i] === undefined)) {
      delete obj[i];
    } else if (obj[i] === "") {
      delete obj[i];
    } else if (typeof obj[i] === 'object') {
      if (Object.keys(obj[i]).length) {
        deleteNullProps(obj[i]);
      } else {
        delete obj[i];
      }
    }
  }
  return obj;
}

deleteProp = function(obj, del) {
  var copy = extend(obj);
  for (var i = 0; i < del.length; i++) {
    var elem = del[i];
    delete copy[elem];
  };
  return copy;
}

// jsonToCSV = function(objArray, config) {
//   return Papa.unparse(objArray, {
//     quotes: false,
//     delimiter: config.delimiter,
//     newline: config.newline
//   });
// }

jsonToCSV = function(objArray, config) {
  var defaults = {
    delimiter: ',',
    newline: '\n'
  };
  var opt = config || defaults;
  var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
  var str = '';

  for (var i = 0; i < array.length; i++) {
    var line = '';

    for (var j = 0; j < array[i].length; j++) {
      if (line != '') { line += opt.delimiter };
      line += array[i][j];
    }

    if (i === array.length - 1) {
      str += line;
    } else {
      str += line + opt.newline;
    }
  }
  return str;
}

csvFormat = function(obj) {
  if (!isEmpty(obj)) {
    var data = obj.data;
    if (obj.x_axis.scale === "time" || obj.x_axis.scale === "ordinal-time") {
      var stdFormat = app_settings.chart.date_format;
      if (obj.hasHours) { stdFormat += " " + app_settings.chart.time_format; }
      var currFormat = obj.date_format;
      return standardizeDates(data, currFormat, stdFormat);
    } else {
      return data;<commit_msg>wraps csv values with commas with quote marks<commit_after>randomFromArr = function(arr) {
  return arr[Math.floor(Math.random() * arr.length)];
}

extend = function(from, to) {
  if (from == null || typeof from != "object") return from;
  if (from.constructor != Object && from.constructor != Array) return from;
  if (from.constructor == Date || from.constructor == RegExp || from.constructor == Function ||
    from.constructor == String || from.constructor == Number || from.constructor == Boolean)
    return new from.constructor(from);

  to = to || new from.constructor();

  for (var name in from) {
    to[name] = typeof to[name] == "undefined" ? extend(from[name], null) : to[name];
  }

  return to;
}

isEmpty = function(obj) {
  return Object.keys(obj).length === 0;
}

escapeStr = function(str) {
  if (typeof str === "string") {
    return str ? str.replace(/\"/g, '\\\"') : str;
  }
}

cleanEmbed = function(data) {
  var arr = [];
  arr.push(
    "_id",
    "slug",
    "createdAt",
    "lastEdited",
    "version",
    "build",
    "heading",
    "qualifier",
    "source",
    "md5",
    "date_format",
    "time_format",
    "print",
    "img",
    "prefix",
    "series",
    "annotations",
    "range",
    "public",
    "users",
    "tags"
  );
  var chartObj = deleteProp(data, arr);
  var newData = csvFormat(data);
  chartObj.data = newData;
  return deleteNullProps(chartObj);
}

embed = function(obj) {
  var data = {
    "version": obj.version,
    "id": obj._id,
    "heading": escapeStr(obj.heading),
    "qualifier": escapeStr(obj.qualifier),
    "source": escapeStr(obj.source),
    "tags": escapeStr(obj.tags)
  };
  data["chart"] = cleanEmbed(obj);
  return data;
}

deleteNullProps = function(obj) {
  for (var i in obj) {
    if ((obj[i] === null) || (obj[i] === undefined)) {
      delete obj[i];
    } else if (obj[i] === "") {
      delete obj[i];
    } else if (typeof obj[i] === 'object') {
      if (Object.keys(obj[i]).length) {
        deleteNullProps(obj[i]);
      } else {
        delete obj[i];
      }
    }
  }
  return obj;
}

deleteProp = function(obj, del) {
  var copy = extend(obj);
  for (var i = 0; i < del.length; i++) {
    var elem = del[i];
    delete copy[elem];
  };
  return copy;
}

// jsonToCSV = function(objArray, config) {
//   return Papa.unparse(objArray, {
//     quotes: false,
//     delimiter: config.delimiter,
//     newline: config.newline
//   });
// }

jsonToCSV = function(objArray, config) {
  var defaults = {
    delimiter: ',',
    newline: '\n'
  };
  var opt = config || defaults;
  var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
  var str = '';

  for (var i = 0; i < array.length; i++) {
    var line = '';

    for (var j = 0; j < array[i].length; j++) {
      if (line != '') { line += opt.delimiter };
      if (array[i][j].match(/,/)) {
        line += '\"' + array[i][j] + '\"';
      } else {
        line += array[i][j];
      }

    }

    if (i === array.length - 1) {
      str += line;
    } else {
      str += line + opt.newline;
    }
  }
  return str;
}

csvFormat = function(obj) {
  if (!isEmpty(obj)) {
    var data = obj.data;
    if (obj.x_axis.scale === "time" || obj.x_axis.scale === "ordinal-time") {
      var stdFormat = app_settings.chart.date_format;
      if (obj.hasHours) { stdFormat += " " + app_settings.chart.time_format; }
      var currFormat = obj.date_format;
      return standardizeDates(data, currFormat, stdFormat);
    } else {
      return data;
{'fraction_non_alphanumeric': 0.18196363636363636, 'fraction_numerical': 0.0017454545454545455, 'mean_word_length': 2.6809421841541754, 'pattern_counts': {'":': 12, '<': 9, '<?xml version=': 0, '>': 3, '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': '3355090', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2387, 'n_words': 563}