<commit_before>/*!
 * verb-repo-helpers (https://github.com/verbose/verb-repo-helpers)
 *
 * Copyright (c) 2016, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

var fs = require('fs');
var util = require('util');
var path = require('path');
var debug = require('debug')('base:verb:readme-generator');
var utils = require('./utils');

module.exports = function plugin(app) {
  if (!this.isApp) return;
  if (this.isRegistered('verb-repo-helpers')) return;
  debug('initializing <%s>, called by <%s>', __filename, module.parent.id);

  app.asyncHelper('section', function(name, options, cb) {
    if (options === 'function') {
      cb = options;
      options = {};
    }
    var view = app.includes.getView(name);
    if (typeof view === 'undefined') {
      cb(null, '');
      return;
    }
    app.render(view, function(err, res) {
      if (err) return cb(err);
      cb(null, res.content);
    });
  });

  app.asyncHelper('block', function(name, options, cb) {
    app.include(name, options.fn(this));
    cb(null, '');
  });

  /**
   * async helpers
   */

  app.asyncHelper('related', function() {
    return utils.related(this.options).apply(this, arguments);
  });

  app.asyncHelper('reflinks', function() {
    return utils.reflinks(this.options).apply(this, arguments);
  });

  /**
   * Add a github contributors list from GitHub's API
   */

  app.helperGroup('gh', {
    contributors: function(repo, options, cb) {
      if (typeof repo === 'function') {
        cb = repo;
        options = {};
        repo = null;
      }
      if (typeof options === 'function') {
        cb = options;
        options = {};
      }
      if (typeof repo !== 'string') {
        options = repo;
        repo = null;
      }
      options = options || this.options;
      repo = repo || this.context.repository;
      return utils.contributors(repo, options, cb);
    }
  }, true);

  /**
   * Create a GitHub issue linke
   */

  app.helper('issue', function(options) {
    var opts = utils.merge({}, this.context, options);
    opts.owner = opts.owner || opts.author && opts.author.username;
    opts.repo = opts.name;
    return utils.issue(opts);
  });

  /**
   * Return `val` if a file or one of the given `files` exists on the file system.
   */

  app.asyncHelper('ifExists', function(files, val, cb) {
    if (utils.exists(files, app.cwd)) {
      cb(null, val);
    } else {
      cb(null, '');
    }
  });

  app.asyncHelper('maybeInclude', function maybe(name, helperName, cb) {
    if (typeof helperName === 'function') {
      cb = helperName;
      helperName = 'include';
    }

    var opts = utils.merge({}, this.options, this.context);
    if (opts[name]) {
      var fn = app.getAsyncHelper(helperName);
      return fn.apply(this, arguments);
    } else {
      cb(null, '');
    }
  });

  /**
   * Get a package.json from npm's API
   */

  app.asyncHelper('pkg', function fn(name, prop, cb) {
    if (typeof prop === 'function') {
      cb = prop;
      prop = null;
    }

    var key = name + ':' + String(prop);
    if (fn[key]) {
      cb(null, fn[key]);
      return;
    }

    utils.getPkg(name, function(err, pkg) {
      if (err) return cb(err);
      var res = prop ? utils.get(pkg, prop) : pkg;
      fn[key] = res;
      cb(null, res);
    });
  });

  app.asyncHelper('read', function(fp, cb) {
    fs.readFile(fp, 'utf8', cb);
  });

  /**
   * sync helpers
   */

  app.helper('require', function(name) {
    try {
      return require(name);
    } catch (err) {}
    try {
      return require(path.resolve(name));
    } catch (err) {}
    return '';
  });

  // date helper
  app.helper('date', function() {
    return utils.date.apply(this, arguments);
  });

  app.helper('apidocs', function() {
    var fn = utils.apidocs(this.options);
    return fn.apply(null, arguments);
  });

  app.helper('copyright', function() {
    var fn = utils.copyright({linkify: true});
    return fn.apply(this, arguments);
  });

  /**
   * Display a commented line of code
   */

  app.helper('results', function(val) {
    var fn = require(utils.resolve.sync(app.cwd));
    var lines = util.inspect(fn(val)).split('\n');
    return lines.map(function(line) {
      return '//' + line;
    }).join('\n');
  });

  app.helper('previous', function(increment, v) {
    var segs = String(v).split('.');
    var version = '';
    switch (increment) {
      case 'major':
        version = (segs[0] - 1) + '.0.0';
        break;
      case 'minor':
      default: {
        version = segs[0] + '.' + (segs[1] - 1) + '.0';
        break;
      }
    }
    return version;
  });

  debug('helpers finished');
  return plugin;
};
<commit_msg>allow second arg to `section` to be a string<commit_after>/*!
 * verb-repo-helpers (https://github.com/verbose/verb-repo-helpers)
 *
 * Copyright (c) 2016, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

var fs = require('fs');
var util = require('util');
var path = require('path');
var debug = require('debug')('base:verb:readme-generator');
var utils = require('./utils');

module.exports = function plugin(app) {
  if (!this.isApp) return;
  if (this.isRegistered('verb-repo-helpers')) return;
  debug('initializing <%s>, called by <%s>', __filename, module.parent.id);

  app.asyncHelper('section', function(name, locals, cb) {
    if (typeof locals === 'function') {
      cb = locals;
      locals = {};
    }
    var view = app.includes.getView(name);
    var fallback = '';

    if (typeof locals === 'string') {
      fallback = locals;
    }

    if (typeof view === 'undefined') {
      cb(null, fallback);
      return;
    }
    app.render(view, locals, function(err, res) {
      if (err) return cb(err);
      cb(null, res.content);
    });
  });

  app.asyncHelper('block', function(name, options, cb) {
    app.include(name, options.fn(this));
    cb(null, '');
  });

  /**
   * async helpers
   */

  app.asyncHelper('related', function() {
    return utils.related(this.options).apply(this, arguments);
  });

  app.asyncHelper('reflinks', function() {
    return utils.reflinks(this.options).apply(this, arguments);
  });

  /**
   * Add a github contributors list from GitHub's API
   */

  app.helperGroup('gh', {
    contributors: function(repo, options, cb) {
      if (typeof repo === 'function') {
        cb = repo;
        options = {};
        repo = null;
      }
      if (typeof options === 'function') {
        cb = options;
        options = {};
      }
      if (typeof repo !== 'string') {
        options = repo;
        repo = null;
      }
      options = options || this.options;
      repo = repo || this.context.repository;
      return utils.contributors(repo, options, cb);
    }
  }, true);

  /**
   * Create a GitHub issue linke
   */

  app.helper('issue', function(options) {
    var opts = utils.merge({}, this.context, options);
    opts.owner = opts.owner || opts.author && opts.author.username;
    opts.repo = opts.name;
    return utils.issue(opts);
  });

  /**
   * Return `val` if a file or one of the given `files` exists on the file system.
   */

  app.asyncHelper('ifExists', function(files, val, cb) {
    if (utils.exists(files, app.cwd)) {
      cb(null, val);
    } else {
      cb(null, '');
    }
  });

  app.asyncHelper('maybeInclude', function maybe(name, helperName, cb) {
    if (typeof helperName === 'function') {
      cb = helperName;
      helperName = 'include';
    }

    var opts = utils.merge({}, this.options, this.context);
    if (opts[name]) {
      var fn = app.getAsyncHelper(helperName);
      return fn.apply(this, arguments);
    } else {
      cb(null, '');
    }
  });

  /**
   * Get a package.json from npm's API
   */

  app.asyncHelper('pkg', function fn(name, prop, cb) {
    if (typeof prop === 'function') {
      cb = prop;
      prop = null;
    }

    var key = name + ':' + String(prop);
    if (fn[key]) {
      cb(null, fn[key]);
      return;
    }

    utils.getPkg(name, function(err, pkg) {
      if (err) return cb(err);
      var res = prop ? utils.get(pkg, prop) : pkg;
      fn[key] = res;
      cb(null, res);
    });
  });

  app.asyncHelper('read', function(fp, cb) {
    fs.readFile(fp, 'utf8', cb);
  });

  /**
   * sync helpers
   */

  app.helper('require', function(name) {
    try {
      return require(name);
    } catch (err) {}
    try {
      return require(path.resolve(name));
    } catch (err) {}
    return '';
  });

  // date helper
  app.helper('date', function() {
    return utils.date.apply(this, arguments);
  });

  app.helper('apidocs', function() {
    var fn = utils.apidocs(this.options);
    return fn.apply(null, arguments);
  });

  app.helper('copyright', function() {
    var fn = utils.copyright({linkify: true});
    return fn.apply(this, arguments);
  });

  /**
   * Display a commented line of code
   */

  app.helper('results', function(val) {
    var fn = require(utils.resolve.sync(app.cwd));
    var lines = util.inspect(fn(val)).split('\n');
    return lines.map(function(line) {
      return '//' + line;
    }).join('\n');
  });

  app.helper('previous', function(increment, v) {
    var segs = String(v).split('.');
    var version = '';
    switch (increment) {
      case 'major':
        version = (segs[0] - 1) + '.0.0';
        break;
      case 'minor':
      default: {
        version = segs[0] + '.' + (segs[1] - 1) + '.0';
        break;
      }
    }
    return version;
  });

  debug('helpers finished');
  return plugin;
};

{'fraction_non_alphanumeric': 0.17936842105263157, 'fraction_numerical': 0.0027368421052631577, 'mean_word_length': 2.489166360631656, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5839386', 'n_tokens_mistral': 3173, 'n_tokens_neox': 3117, 'n_words': 731}