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

'use strict';

module.exports = function(grunt) {

  var pParser = require('properties-parser');

  // Please see the Grunt documentation for more information regarding task
  // creation: http://gruntjs.com/creating-tasks

  grunt.registerMultiTask('properties', 'Convert java .properties files to javascript', function() {
    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
          namespace: 'config'
        }),
        src = 'var ' + options.namespace + ' = ' + options.namespace + ' || {};\n';

    function convert(filepath) {
      var fileContent = grunt.file.read(filepath),
          ns = options.namespace,
          exp = null,
          code = [];

      fileContent = pParser.parse(fileContent);

      for (var file in fileContent) {
        exp = ns + '.' + file + ' = "' + fileContent[file] + '";';
        code.push(exp);
      }

      return code.join('\n');
    }

    // Iterate over all specified file groups.
    this.files.forEach(function(f) {

      // Concat specified files.
      src += f.src.filter(function(filepath) {
        // Warn on and remove invalid source files (if nonull was set).
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('.properties file "' + filepath + '" not found.');
          return false;
        } else {
          return true;
        }
      }).map(convert).join('\n');

      // Write the destination file.
      grunt.file.write(f.dest, src);
<commit_msg>2 minor improvements for grunt-properties plugin<commit_after>/*
 * grunt-properties
 * https://github.com/helder/grunt-properties
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  var pParser = require('properties-parser');

  // Please see the Grunt documentation for more information regarding task
  // creation: http://gruntjs.com/creating-tasks

  grunt.registerMultiTask('properties', 'Convert java .properties files to javascript', function() {
    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
          namespace: 'config'
        }),
        useNS = options.namespace.length > 0,
        src = useNS === false ? '{\n' :
            'var ' + options.namespace + ' = ' + options.namespace + ' || {};\n';

    function convert(filepath) {
      var fileContent = grunt.file.read(filepath),
          ns = options.namespace,
          exp = null,
          code = [];

      fileContent = pParser.parse(fileContent);

      for (var file in fileContent) {
        exp =
            (useNS ? ns + '[' : '  ') + '"' + file + '"' +
            (useNS ? ']' : '') + (useNS ? ' = ' : ': ') + '"' +
            fileContent[file] + '"' + (useNS ? ';' : ',');

        code.push(exp);
      }

      return code.join('\n');
    }

    // Iterate over all specified file groups.
    this.files.forEach(function(f) {

      // Concat specified files.
      src += f.src.filter(function(filepath) {
        // Warn on and remove invalid source files (if nonull was set).
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('.properties file "' + filepath + '" not found.');
          return false;
        } else {
          return true;
        }
      }).map(convert).join('\n');

      if (useNS !== true) {
        src = src.substring(0, src.length - 1) + '\n};';
      }

      // Write the destination file.
      grunt.file.write(f.dest, src);

{'fraction_non_alphanumeric': 0.14976769609182836, 'fraction_numerical': 0.003279584585952446, 'mean_word_length': 2.2077125328659073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '7349456', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1061, 'n_words': 269}