<commit_before>/* ==========================================================================
   Dox-ray
   Parse documentation from code comments
   ========================================================================== */

var Doxray = function() {};

Doxray.prototype.logMessages = {
  parseGotWrongType: 'parse() expected a String or an Array.',
  parsedDocsDoesNotMatchParsedCode: 'Parsing failed because the number of parsed doc comments does not match the number of parsed code snippets.'
}

Doxray.prototype.run = function( src, options, callback ) {
  var parsed, processed;
  src = this.handleSrc( src );
  options = this.handleOptions( options );
  parsed = this.parse( src, options.merge );
  processed = this.postParseProcessing( parsed );
  if ( options.jsonFile ) {
    this.writeJSON( processed, options.jsonFile, callback );
  }
  if ( options.jsFile ) {
    this.writeJS( processed, options.jsFile, callback );
  }
  return processed;
};

Doxray.prototype.handleSrc = function( src ) {
  var glob = require("glob");
  var fileToTest;
  if ( typeof src === 'string' ) {
    src = glob.sync( src );
  }
  return src;
};

Doxray.prototype.handleOptions = function( options ) {
  if ( typeof options !== 'object' ) {
    options = {};
  }
  options.jsFile = options.jsFile;
  options.jsonFile = options.jsonFile;
  if ( typeof options.merge === 'undefined' ) {
    options.merge = true;
  }
  return options;
};

Doxray.prototype.jsonWhiteSpace = 2;

Doxray.prototype.writeJSON = function( convertedDocs, dest, callback ) {
  var fs = require('fs');
  var convertedDocsAsString = JSON.stringify( convertedDocs.patterns, null, this.jsonWhiteSpace );
  fs.writeFile( dest, convertedDocsAsString, function( err ) {
    if ( err ) {
      throw err;
      // TODO: A node.js equivalent to Grunts this.async( err );
    }
    console.log( dest, 'was created.' );
    if ( typeof callback === 'undefined' ) return;
    callback();
    // TODO: A node.js equivalent to Grunts this.async();
  });
};

// The following function was referenced from:
// https://gist.github.com/cowboy/3749767
Doxray.prototype.stringify = function( obj, prop ) {
  var placeholder = '____PLACEHOLDER____';
  var fns = [];
  var json = JSON.stringify( obj, function( key, value ) {
    if ( typeof value === 'function' ) {
      fns.push( value );
      return placeholder;
    }
    return value;
  }, this.jsonWhiteSpace);
  json = json.replace( new RegExp( '"' + placeholder + '"', 'g' ), function(_) {
    return fns.shift();
  });
  return 'var ' + prop + ' = ' + json + ';';
};

Doxray.prototype.writeJS = function( convertedDocs, dest, callback ) {
  var fs = require('fs');
  var convertedDocsAsString = this.stringify( convertedDocs, 'Doxray' );
  fs.writeFile( dest, convertedDocsAsString, 'utf-8', function( err ) {
    if ( err ) {
      throw err;
      // TODO: A node.js equivalent to Grunts this.async( err );
    }
    console.log( dest, 'was created.' );
    if ( typeof callback === 'undefined' ) return;
    callback();
    // TODO: A node.js equivalent to Grunts this.async();
  });
};

Doxray.prototype.processors = [
  require('./processors/filters.js'),
  require('./processors/slugify.js'),
  require('./processors/color-palette.js')
];

Doxray.prototype.postParseProcessing = function( parsed ) {
  var processedDocs = {
      patterns: parsed
  };
  if ( typeof this.processors !== 'undefined' ) {
    this.processors.forEach(function( processor ){
      processedDocs = processor( processedDocs );
    });
  }
  return processedDocs;
};

Doxray.prototype.parse = function( src, merge ) {<commit_msg>Removes some out of date comments.<commit_after>/* ==========================================================================
   Dox-ray
   Parse documentation from code comments
   ========================================================================== */

var Doxray = function() {};

Doxray.prototype.logMessages = {
  parseGotWrongType: 'parse() expected a String or an Array.',
  parsedDocsDoesNotMatchParsedCode: 'Parsing failed because the number of parsed doc comments does not match the number of parsed code snippets.'
}

Doxray.prototype.run = function( src, options, callback ) {
  var parsed, processed;
  src = this.handleSrc( src );
  options = this.handleOptions( options );
  parsed = this.parse( src, options.merge );
  processed = this.postParseProcessing( parsed );
  if ( options.jsonFile ) {
    this.writeJSON( processed, options.jsonFile, callback );
  }
  if ( options.jsFile ) {
    this.writeJS( processed, options.jsFile, callback );
  }
  return processed;
};

Doxray.prototype.handleSrc = function( src ) {
  var glob = require("glob");
  var fileToTest;
  if ( typeof src === 'string' ) {
    src = glob.sync( src );
  }
  return src;
};

Doxray.prototype.handleOptions = function( options ) {
  if ( typeof options !== 'object' ) {
    options = {};
  }
  options.jsFile = options.jsFile;
  options.jsonFile = options.jsonFile;
  if ( typeof options.merge === 'undefined' ) {
    options.merge = true;
  }
  return options;
};

Doxray.prototype.jsonWhiteSpace = 2;

Doxray.prototype.writeJSON = function( convertedDocs, dest, callback ) {
  var fs = require('fs');
  var convertedDocsAsString = JSON.stringify( convertedDocs.patterns, null, this.jsonWhiteSpace );
  fs.writeFile( dest, convertedDocsAsString, function( err ) {
    if ( err ) {
      throw err;
    }
    console.log( dest, 'was created.' );
    if ( typeof callback === 'undefined' ) return;
    callback();
  });
};

// The following function was referenced from:
// https://gist.github.com/cowboy/3749767
Doxray.prototype.stringify = function( obj, prop ) {
  var placeholder = '____PLACEHOLDER____';
  var fns = [];
  var json = JSON.stringify( obj, function( key, value ) {
    if ( typeof value === 'function' ) {
      fns.push( value );
      return placeholder;
    }
    return value;
  }, this.jsonWhiteSpace);
  json = json.replace( new RegExp( '"' + placeholder + '"', 'g' ), function(_) {
    return fns.shift();
  });
  return 'var ' + prop + ' = ' + json + ';';
};

Doxray.prototype.writeJS = function( convertedDocs, dest, callback ) {
  var fs = require('fs');
  var convertedDocsAsString = this.stringify( convertedDocs, 'Doxray' );
  fs.writeFile( dest, convertedDocsAsString, 'utf-8', function( err ) {
    if ( err ) {
      throw err;
    }
    console.log( dest, 'was created.' );
    if ( typeof callback === 'undefined' ) return;
    callback();
  });
};

Doxray.prototype.processors = [
  require('./processors/filters.js'),
  require('./processors/slugify.js'),
  require('./processors/color-palette.js')
];

Doxray.prototype.postParseProcessing = function( parsed ) {
  var processedDocs = {
      patterns: parsed
  };
  if ( typeof this.processors !== 'undefined' ) {
    this.processors.forEach(function( processor ){
      processedDocs = processor( processedDocs );
    });
  }
  return processedDocs;
};

Doxray.prototype.parse = function( src, merge ) {
{'fraction_non_alphanumeric': 0.1785867237687366, 'fraction_numerical': 0.002569593147751606, 'mean_word_length': 3.564169381107492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '160083', 'n_tokens_mistral': 2137, 'n_tokens_neox': 2110, 'n_words': 537}