<commit_before>/**
 * Utility module that loads modules according to passed map of modules.
 * @module util/moduleLoader
 */

/**
 * Module initializer.
 */
module.exports = function (app) {

  /**
   * Error messages map.
   * @const
   */
  var ERRS = {
    '!app': 'moduleLoader requires an top level namespace containing'
        + ' the root require function and standard loggers',
    '!modules_map': 'moduleLoader requires an object with modules to load'
        + ' as its first argument',
    'app.require fail': 'could not load module, error message below'
  };

  if (!app || typeof app !== 'object') {
    throw new Error(ERRS['!app']);
  }

  /**
   * Requires modules and returns them in an object
   * @param {object} modules_map - Key value map of modules to load
   * @return {object} modules - Key value map of loaded modules
   * @example
   * app.modules = require('lib/util/moduleLoader')({
   *   fs: 'fs',
   *   cls: 'opensoars_cls'
   * });
   */
  function moduleLoader(modules_map) {
    var modules = {},
        module_name,
        module;

    if (!modules_map || typeof modules_map !== 'object') {
      throw new Error(ERRS['!modules_map']);
    }

    for (module_name in modules_map) {
      try {
        module = app.require(module_name);
        modules[module_name] = module;
      } catch (e) {
        throw new Error(ERRS['app.require fail'] + '\n' + e.message)<commit_msg>Wrapped for in loop in if statement<commit_after>/**
 * Utility module that loads modules according to passed map of modules.
 * @module util/moduleLoader
 */

/**
 * Module initializer.
 */
module.exports = function (app) {

  /**
   * Error messages map.
   * @const
   */
  var ERRS = {
    '!app': 'moduleLoader requires an top level namespace containing'
        + ' the root require function and standard loggers',
    '!modules_map': 'moduleLoader requires an object with modules to load'
        + ' as its first argument',
    'app.require fail': 'could not load module, error message below'
  };

  if (!app || typeof app !== 'object') {
    throw new Error(ERRS['!app']);
  }

  /**
   * Requires modules and returns them in an object
   * @param {object} modules_map - Key value map of modules to load
   * @return {object} modules - Key value map of loaded modules
   * @example
   * app.modules = require('lib/util/moduleLoader')({
   *   fs: 'fs',
   *   cls: 'opensoars_cls'
   * });
   */
  function moduleLoader(modules_map) {
    var modules = {},
        module_name,
        module;

    if (!modules_map || typeof modules_map !== 'object') {
      throw new Error(ERRS['!modules_map']);
    }

    for (module_name in modules_map) {
      if( modules_map.hasOwnProperty(module_name) ){
        try {
          module = app.require(module_name);
          modules[module_name] = module;
        } catch (e) {
          throw new Error(ERRS['app.require fail'] + '\n' + e.message)
        }
{'fraction_non_alphanumeric': 0.12957264957264958, 'fraction_numerical': 0.0, 'mean_word_length': 2.6758793969849246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5912913', 'n_tokens_mistral': 875, 'n_tokens_neox': 864, 'n_words': 277}