<commit_before>/**
 * Generate node module API markdown with dox
 *
 * Licensed under MIT.
 * Copyright (c) 2013 <NAME> <https://github.com/codeactual/>
 */

/*jshint node:true*/
'use strict';

/**
 * GitemplateDox constructor.
 */
exports.GitemplateDox = GitemplateDox;

/**
 * Create a new GitemplateDox.
 *
 * @return {object}
 */
exports.create = function() { return new GitemplateDox(); };

/**
 * Extend GitemplateDox.prototype.
 *
 * @param {object} ext
 * @return {object} Merge result.
 */
exports.extend = function(ext) { return extend(GitemplateDox.prototype, ext); };

var dox = require('dox');
var fs = require('fs');
var path = require('path');
var util = require('util');
var sprintf = util.format;

var requireComponent = require('../component/require');
var extend = requireComponent('extend');
var configurable = requireComponent('configurable.js');

/**
 * GitemplateDox constructor.
 *
 *
 * Usage:
 *
 *     var dox = require('gitemplate-dox').create();
 *     var markdown = dox
 *       .set('input', '/path/to/source.js')
 *       .set('output', '/path/to/output.md')
 *       .parse()
 *       .convert();
 *
 * Configuration:
 *
 * - `{string} [input]` Source file to read
 * - `{string} [output]` Markdown file to write
 *
 * Properties:
 *
 * - `{array} [comments=[]]` Filtered dox-provided objects to convert
 * - `{object} [fileComment={}]` First dox-provided comment found in the file
 * - `{array} [lines=[]]` Markdown lines
 * - `{object} [params={}]` Collected `@param` meta indexed by method name
 *   - `{array} types` Type names
 *   - `{string} description` First line
 *   - `{array} overflow` Additional lines
 * - `{object} [returns={}]` Collected `@return` metadata indexed by method name
 *   - `{array} types` Type names
 *   - `{string} description` First line
 *   - `{array} overflow` Additional lines
 * - `{array} [sees=[]]` Collected `@see` lines
 * - `{array} [toc=[]]` Collected table-of-contents metadata objects
 *   - `{string} title` Link title
 *   - `{string} url` Link URL
 *
 */
function GitemplateDox() {
  this.settings = {input: '', output: ''};
  this.comments = [];
  this.fileComment = {};
  this.lines = [];
  this.params = {};
  this.returns = {};
  this.sees = [];
  this.toc = [];
}

configurable(GitemplateDox.prototype);

// ===================== PUBLIC =====================

/**
 * Parse the source file.
 *
 * @param {string} file
 * @see GitemplateDox.prototype.convert
 */
GitemplateDox.prototype.parse = function() {
  var text = fs.readFileSync(this.get('input')).toString();
  dox.parseComments(text, {raw: true}).forEach(this.parseComment.bind(this));
};

/**
 * Convert comments to markdown.
 *
 * @return {string}
 */
GitemplateDox.prototype.convert = function() {
  this.comments.forEach(this.collectParams.bind(this));
  this.comments.forEach(this.convertOne.bind(this));
  this.prependTOC();
  return this.lines.join('\n').trim() + '\n';
};

// ===================== PRIVATE: PARSING =====================

/**
 * Convert one parsed comment to markdown line(s).
 *
 * @param {Markdown} Line collection
 * @param {object} comment
 * @api private
 */<commit_msg>docs(lib): Remove debugging @see<commit_after>/**
 * Generate node module API markdown with dox
 *
 * Licensed under MIT.
 * Copyright (c) 2013 <NAME> <https://github.com/codeactual/>
 */

/*jshint node:true*/
'use strict';

/**
 * GitemplateDox constructor.
 */
exports.GitemplateDox = GitemplateDox;

/**
 * Create a new GitemplateDox.
 *
 * @return {object}
 */
exports.create = function() { return new GitemplateDox(); };

/**
 * Extend GitemplateDox.prototype.
 *
 * @param {object} ext
 * @return {object} Merge result.
 */
exports.extend = function(ext) { return extend(GitemplateDox.prototype, ext); };

var dox = require('dox');
var fs = require('fs');
var path = require('path');
var util = require('util');
var sprintf = util.format;

var requireComponent = require('../component/require');
var extend = requireComponent('extend');
var configurable = requireComponent('configurable.js');

/**
 * GitemplateDox constructor.
 *
 *
 * Usage:
 *
 *     var dox = require('gitemplate-dox').create();
 *     var markdown = dox
 *       .set('input', '/path/to/source.js')
 *       .set('output', '/path/to/output.md')
 *       .parse()
 *       .convert();
 *
 * Configuration:
 *
 * - `{string} [input]` Source file to read
 * - `{string} [output]` Markdown file to write
 *
 * Properties:
 *
 * - `{array} [comments=[]]` Filtered dox-provided objects to convert
 * - `{object} [fileComment={}]` First dox-provided comment found in the file
 * - `{array} [lines=[]]` Markdown lines
 * - `{object} [params={}]` Collected `@param` meta indexed by method name
 *   - `{array} types` Type names
 *   - `{string} description` First line
 *   - `{array} overflow` Additional lines
 * - `{object} [returns={}]` Collected `@return` metadata indexed by method name
 *   - `{array} types` Type names
 *   - `{string} description` First line
 *   - `{array} overflow` Additional lines
 * - `{array} [sees=[]]` Collected `@see` lines
 * - `{array} [toc=[]]` Collected table-of-contents metadata objects
 *   - `{string} title` Link title
 *   - `{string} url` Link URL
 *
 */
function GitemplateDox() {
  this.settings = {input: '', output: ''};
  this.comments = [];
  this.fileComment = {};
  this.lines = [];
  this.params = {};
  this.returns = {};
  this.sees = [];
  this.toc = [];
}

configurable(GitemplateDox.prototype);

// ===================== PUBLIC =====================

/**
 * Parse the source file.
 *
 * @param {string} file
 */
GitemplateDox.prototype.parse = function() {
  var text = fs.readFileSync(this.get('input')).toString();
  dox.parseComments(text, {raw: true}).forEach(this.parseComment.bind(this));
};

/**
 * Convert comments to markdown.
 *
 * @return {string}
 */
GitemplateDox.prototype.convert = function() {
  this.comments.forEach(this.collectParams.bind(this));
  this.comments.forEach(this.convertOne.bind(this));
  this.prependTOC();
  return this.lines.join('\n').trim() + '\n';
};

// ===================== PRIVATE: PARSING =====================

/**
 * Convert one parsed comment to markdown line(s).
 *
 * @param {Markdown} Line collection
 * @param {object} comment
 * @api private
 */
{'fraction_non_alphanumeric': 0.2044331047679796, 'fraction_numerical': 0.0012757136022962844, 'mean_word_length': 3.7587253414264037, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5187691', 'n_tokens_mistral': 2089, 'n_tokens_neox': 2030, 'n_words': 493}