<commit_before>/*!
 * minimist-events <https://github.com/jonschlinkert/minimist-events>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

var Emitter = require('component-emitter');
var forward = require('forward-object');
var extend = require('extend-shallow');

module.exports = function (options) {
  if (typeof options === 'function') {
    return events.apply(events, arguments);
  }

  function events(minimist, opts) {
    opts = extend({}, options, opts);
    var fn = minimist;

    if (typeof fn !== 'function') {
      throw new TypeError('expected minimist to be a function.');
    }

    opts = opts || {};

    var proxy = Emitter(function () {
      var argv = fn.apply(fn, arguments);
      if (typeof opts.postProcess === 'function') {
        argv = opts.postProcess(argv);
      }

      var keys = Object.keys(argv);
      proxy.argv = argv;

      if (opts.help && !argv._.length && keys.length === 1) {
        proxy.emit('help');
        return argv;
      }

      keys.forEach(function (key) {
        var val = argv[key];
        proxy.emit(key, val);
        proxy.emit('*', key, val);

        if (key === '_') {
          val.forEach(function (k, i) {
            proxy.emit(i, k, val);
            proxy.emit(k, i, val);
          });
        }
      });

      proxy.emit('end');
      return argv;
    });

    forward(proxy, fn);
    return proxy;
  };

  return minimistEvents;
};
<commit_msg>emit non-option args first.<commit_after>/*!
 * minimist-events <https://github.com/jonschlinkert/minimist-events>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

var Emitter = require('component-emitter');
var forward = require('forward-object');
var extend = require('extend-shallow');

module.exports = function (options) {
  if (typeof options === 'function') {
    return events.apply(events, arguments);
  }

  function events(minimist, opts) {
    opts = extend({}, options, opts);
    var fn = minimist;

    if (typeof fn !== 'function') {
      throw new TypeError('expected minimist to be a function.');
    }

    opts = opts || {};

    var proxy = Emitter(function () {
      var argv = fn.apply(fn, arguments);
      if (typeof opts.postProcess === 'function') {
        argv = opts.postProcess(argv);
      }

      var keys = Object.keys(argv);
      proxy.argv = argv;

      if (opts.help && !argv._.length && keys.length === 1) {
        proxy.emit('help');
        return argv;
      }

      // ensure that `_` args are emitted first
      proxy.emit('_', argv._);
      proxy.emit('*', '_', argv._);

      argv._.forEach(function (k, i) {
        proxy.emit(i, k, argv._);
        proxy.emit(k, i, argv._);
      });

      // after `_`, emit options args
      keys.forEach(function (key) {
        if (key === '_') return;
        var val = argv[key];
        proxy.emit(key, val);
        proxy.emit('*', key, val);
      });

      proxy.emit('end');
      return argv;
    });

    forward(proxy, fn);
    return proxy;
  }

  return events;
};

{'fraction_non_alphanumeric': 0.16612589227774172, 'fraction_numerical': 0.003244646333549643, 'mean_word_length': 2.3293736501079914, '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': '4677638', 'n_tokens_mistral': 983, 'n_tokens_neox': 944, 'n_words': 244}