<commit_before>'use strict';
let Step = require('./step');
let container = require('./container');
let methodsOfObject = require('./utils').methodsOfObject;
let recorder = require('./recorder');
let event = require('./event');
let output = require('./output');

/**
 * Fetches all methods from all enabled helpers,
 * and makes them available to use from I. object
 * Wraps helper methods into promises.
 */
module.exports = function (obj) {
  obj = obj || {};

  let helpers = container.helpers();

  // add methods from enabled helpers
  Object.keys(helpers)
    .map((key) => helpers[key])
    .forEach((helper) => {
      methodsOfObject(helper, 'Helper')
      .filter((method) => {
        return method !== 'constructor' && method[0] !== '_';
      })
      .forEach((action) => {
        let actionAlias = container.translation().actionAliasFor(action);

        obj[action] = obj[actionAlias] = function () {
          let step = new Step(helper, action);
          if (container.translation().loaded) {
            step.name = actionAlias;
            step.actor = container.translation().I;
          }
          // add methods to promise chain
          return recordStep(step, Array.prototype.slice.call(arguments));
        };
      });
    });

  // add print comment method`
  obj.say = (msg) => recorder.add(`say ${msg}`, () => output.say(msg));

  return obj;
};

function recordStep(step, args) {
  step.status = 'queued';
  step.setArguments(args);

  // run async before step hooks
  event.emit(event.step.before, step);

  let task = `${step.name}: ${step.humanizeArgs()}`;
  let val;

  // run step inside promise
  recorder.add(task, () => {
    event.emit(event.step.started, step);
    step.startTime = +new Date();
    return val = step.run.apply(step, args);
  });

  event.emit(event.step.after, step);

  recorder.add(`step passed`, () => {
    step.endTime = +new Date();
    event.emit(event.step.passed, step);
  });

  recorder.catchWithoutStop((err) => {
    step.endTime = +new Date();
    event.emit(event.step.failed, step);<commit_msg>Modernize JS a bit (#608)<commit_after>'use strict';
let Step = require('./step');
let container = require('./container');
let methodsOfObject = require('./utils').methodsOfObject;
let recorder = require('./recorder');
let event = require('./event');
let output = require('./output');

/**
 * Fetches all methods from all enabled helpers,
 * and makes them available to use from I. object
 * Wraps helper methods into promises.
 */
module.exports = function (obj) {
  obj = obj || {};

  let helpers = container.helpers();

  // add methods from enabled helpers
  Object.keys(helpers)
    .map((key) => helpers[key])
    .forEach((helper) => {
      methodsOfObject(helper, 'Helper')
      .filter((method) => {
        return method !== 'constructor' && method[0] !== '_';
      })
      .forEach((action) => {
        let actionAlias = container.translation().actionAliasFor(action);

        obj[action] = obj[actionAlias] = function () {
          let step = new Step(helper, action);
          if (container.translation().loaded) {
            step.name = actionAlias;
            step.actor = container.translation().I;
          }
          // add methods to promise chain
          return recordStep(step, Array.from(arguments));
        };
      });
    });

  // add print comment method`
  obj.say = (msg) => recorder.add(`say ${msg}`, () => output.say(msg));

  return obj;
};

function recordStep(step, args) {
  step.status = 'queued';
  step.setArguments(args);

  // run async before step hooks
  event.emit(event.step.before, step);

  let task = `${step.name}: ${step.humanizeArgs()}`;
  let val;

  // run step inside promise
  recorder.add(task, () => {
    event.emit(event.step.started, step);
    step.startTime = Date.now();
    return val = step.run.apply(step, args);
  });

  event.emit(event.step.after, step);

  recorder.add(`step passed`, () => {
    step.endTime = Date.now();
    event.emit(event.step.passed, step);
  });

  recorder.catchWithoutStop((err) => {
    step.endTime = Date.now();
    event.emit(event.step.failed, step);
{'fraction_non_alphanumeric': 0.16976575706351124, 'fraction_numerical': 0.001207437816952427, 'mean_word_length': 2.9260663507109004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, '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': '7266268', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1224, 'n_words': 300}