<commit_before>/*
 * grunt-faker
 * https://github.com/chrisocast/grunt-faker
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  var path = require('path');
  var Faker = require('Faker');

  //Loop through entire json object
  function processJson(obj) {
    for (var i in obj) {
      if (typeof(obj[i]) === "object") {
        processJson(obj[i]); // found an obj or array keep digging
      } else if (obj[i] !== null){
        obj[i] = getFunctionNameAndArgs(obj[i]);// not an obj or array, check contents
      }
    }
    return obj;
  }

  // Get func name, extract args, and exec on their values
  function getFunctionNameAndArgs(value) {
    var pattern = /^(.*)\{\{([^()]+?)(\((.+)\))?\}\}(.*)$/g,
    match, func, args;
    var argArray = [], surroundings = [];

    while (match = pattern.exec(value)) {
      surroundings[0] = match[1];
      func = match[2];
      args = match[4];
      surroundings[1] = match[5];
    }

    if (args !== undefined ){
      if (args.indexOf("[") !== -1){
        // is an array as string
        args = JSON.parse(args);
        argArray.push(args);
      } else {
        // one or more string/number params
        args = args.replace(/, /gi, ",");
        args = args.replace(/'/gi, "", "gi");
        argArray = args.split(',');
      }
    }
    // return value if no Faker method is detected
    return func ?
      (surroundings[0] + executeFunctionByName(func,argArray) + surroundings[1]) :
      value;
  }

  // Execute function as string
  function executeFunctionByName(functionName, args) {
    var namespaces = functionName.split(".");
    var nsLength = namespaces.length;
    var context = Faker;
    var parentContext = Faker;

    if (namespaces[0].toLowerCase() === 'definitions'){
      grunt.log.warn('The definitions module from Faker.js is not avail in this task.');
      return;
    }

    for(var i = 0; i < nsLength; i++) {
      context = context[namespaces[i]];
    }

    for(var j = 0; j < nsLength - 1; j++) {
      parentContext = parentContext[namespaces[j]];
    }

    return context.apply(parentContext, args);
  }

  grunt.registerMultiTask('faker', 'Generate fake JSON with faker.', function() {
    
    var options = this.options();
    var outs = Array.isArray(options.out) ? options.out : [options.out];

    // Check that options were provided 
    if(!options.hasOwnProperty("out")){
      grunt.log.warn('"out" option not specified.');
      return false;
    }
    if(Array.isArray(options.jsonFormat)){
      grunt.log.warn('"jsonFormat" option has to be a single file.');
      return false;
    }
    if(!options.hasOwnProperty("jsonFormat")){
      grunt.log.warn('"jsonFormat" option not specified.');
      return false;
    }

    // Check for json format file
    var jsonFormatPath = options.jsonFormat;
    if (!grunt.file.exists(jsonFormatPath)) {
      grunt.log.warn('Format file "' + jsonFormatPath + '" not found.');
      return false;
    }

    outs.forEach(function(outputFilePath) {
      // Create dir if needed
      var destDir = path.dirname(outputFilePath);
      if (!grunt.file.exists(destDir)) {
        grunt.file.mkdir(destDir);
      }

      // Get json and parse with faker
      var json = grunt.file.readJSON(jsonFormatPath);
      var outputJson = processJson(json);

      // Write file with faker json data
      grunt.file.write(outputFilePath, JSON.stringify(outputJson));

      // Print a success message
      grunt.verbose.writeln('File "' + outputFilePath + '" created.');
    });
  });

};<commit_msg>fix wrong number to string conversion<commit_after>/*
 * grunt-faker
 * https://github.com/chrisocast/grunt-faker
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  var path = require('path');
  var Faker = require('Faker');

  //Loop through entire json object
  function processJson(obj) {
    for (var i in obj) {
      if (typeof(obj[i]) === "object") {
        processJson(obj[i]); // found an obj or array keep digging
      } else if (obj[i] !== null){
        obj[i] = getFunctionNameAndArgs(obj[i]);// not an obj or array, check contents
      }
    }
    return obj;
  }

  // Get func name, extract args, and exec on their values
  function getFunctionNameAndArgs(value) {
    var pattern = /^(.*)\{\{([^()]+?)(\((.+)\))?\}\}(.*)$/g,
    match, func, args;
    var argArray = [], surroundings = [];

    while (match = pattern.exec(value)) {
      surroundings[0] = match[1] || null; // if nothing then set the value explicit to null to avoid empty string concatenations
      func = match[2];
      args = match[4];
      surroundings[1] = match[5] || null; // if nothing then set the value explicit to null to avoid empty string concatenations
    }

    if (args !== undefined ){
      if (args.indexOf("[") !== -1){
        // is an array as string
        args = JSON.parse(args);
        argArray.push(args);
      } else {
        // one or more string/number params
        args = args.replace(/, /gi, ",");
        args = args.replace(/'/gi, "", "gi");
        argArray = args.split(',');
      }
    }
    // return value if no Faker method is detected
    return func ?
      (surroundings[0] + executeFunctionByName(func,argArray) + surroundings[1]) :
      value;
  }

  // Execute function as string
  function executeFunctionByName(functionName, args) {
    var namespaces = functionName.split(".");
    var nsLength = namespaces.length;
    var context = Faker;
    var parentContext = Faker;

    if (namespaces[0].toLowerCase() === 'definitions'){
      grunt.log.warn('The definitions module from Faker.js is not avail in this task.');
      return;
    }

    for(var i = 0; i < nsLength; i++) {
      context = context[namespaces[i]];
    }

    for(var j = 0; j < nsLength - 1; j++) {
      parentContext = parentContext[namespaces[j]];
    }

    return context.apply(parentContext, args);
  }

  grunt.registerMultiTask('faker', 'Generate fake JSON with faker.', function() {
    
    var options = this.options();
    var outs = Array.isArray(options.out) ? options.out : [options.out];

    // Check that options were provided 
    if(!options.hasOwnProperty("out")){
      grunt.log.warn('"out" option not specified.');
      return false;
    }
    if(Array.isArray(options.jsonFormat)){
      grunt.log.warn('"jsonFormat" option has to be a single file.');
      return false;
    }
    if(!options.hasOwnProperty("jsonFormat")){
      grunt.log.warn('"jsonFormat" option not specified.');
      return false;
    }

    // Check for json format file
    var jsonFormatPath = options.jsonFormat;
    if (!grunt.file.exists(jsonFormatPath)) {
      grunt.log.warn('Format file "' + jsonFormatPath + '" not found.');
      return false;
    }

    outs.forEach(function(outputFilePath) {
      // Create dir if needed
      var destDir = path.dirname(outputFilePath);
      if (!grunt.file.exists(destDir)) {
        grunt.file.mkdir(destDir);
      }

      // Get json and parse with faker
      var json = grunt.file.readJSON(jsonFormatPath);
      var outputJson = processJson(json);

      // Write file with faker json data
      grunt.file.write(outputFilePath, JSON.stringify(outputJson));

      // Print a success message
      grunt.verbose.writeln('File "' + outputFilePath + '" created.');
    });
  });

};
{'fraction_non_alphanumeric': 0.1487248322147651, 'fraction_numerical': 0.004563758389261745, 'mean_word_length': 2.6099806201550386, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1723507', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2261, 'n_words': 611}