<commit_before>'use strict';

const Handlebars = require('handlebars');
const source = `module.exports = {
{{#each config}}
  {{#if @last}}
  {{@key}}: "{{this}}"
  {{else}}
  {{@key}}: "{{this}}",
  {{/if}}
{{/each}}
};
`;

module.exports = {
  /**
   * Parses a file and returns it as JSON.
   * @param  {string} file
   * @return {Promise}
   */
  parse(file) {
    return new Promise((resolve, reject) => {
      const configAsJson = require(file);

      if (configAsJson) {
        return resolve(configAsJson);
      }

      return reject(`Failed to parse file: ${file}`);
    });
  },

  /**<commit_msg>Handle non-string values<commit_after>'use strict';

const _ = require('lodash');
const Handlebars = require('handlebars');

Handlebars.registerHelper('isString', function(value, options) {
  if (isNaN(value) && !_.includes(['true', 'false', 'null'], value)) {
    return options.fn(this);
  }

  return options.inverse(this);
});

const source = `module.exports = {
{{#each config}}
  {{#if @last}}
  {{#isString this}}
  {{@key}}: '{{this}}'
  {{else}}
  {{@key}}: {{this}}
  {{/isString}}
  {{else}}
  {{@key}}: {{this}},
  {{/if}}
{{/each}}
};
`;

module.exports = {
  /**
   * Parses a file and returns it as JSON.
   * @param  {string} file
   * @return {Promise}
   */
  parse(file) {
    return new Promise((resolve, reject) => {
      const configAsJson = require(file);

      if (configAsJson) {
        return resolve(configAsJson);
      }

      return reject(`Failed to parse file: ${file}`);
    });
  },

  /**
{'fraction_non_alphanumeric': 0.21182586094866795, 'fraction_numerical': 0.0, 'mean_word_length': 3.1621621621621623, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2466882', 'n_tokens_mistral': 536, 'n_tokens_neox': 527, 'n_words': 125}