<commit_before>'use strict';

module.exports = function(options) {
  var useOptions = {
    guessName: function(name) {
      return '';
    }, mapping: {}
  };

  var target = {};
  var handler = {};

  var setMapping = function(items) {
    if (false === (items instanceof Object)) {
      return;
    }

    Object.keys(items).every(function(index) {
      let item = items[index];

      switch (typeof item) {
        case 'string':
          useOptions.mapping[index] = item;
          break;

        case 'object':
        case 'function':
          target[index] = item;
          break;

        default:
          break;
      }
    });
  };

  var setOptions = function(items) {
    if (false === (items instanceof Object)) {
      return;
    }

    if (items.hasOwnProperty('guessName') && ('function' === typeof items.guessName)) {
      useOptions.guessName = items.guessName;
    }

    if (items.hasOwnProperty('mapping')) {
      setMapping(items.mapping);
    }
  };

  var packageName = function(name) {
    return name.trim().replace(/([a-z\d])([A-Z]+)/g, '$1-$2').replace(/[-\s]+/g, '-').toLowerCase();
  };

  var getNames = function(property) {
    const mapping = useOptions.mapping;
    let names = [];

    if (mapping.hasOwnProperty(property)) {
      names.push(mapping[property]);
    }

    names.push(property);
    names.push(packageName(property));

    try {
      let guessName = useOptions.guessName(property);

      if (('string' === typeof guessName) && ('' !== guessName)) {
        names.push(guessName);
      }

      return names;
    } catch (error) {
      return names;
    }
  };

  var getRequire = function(names) {
    let value = null;

    names.every(function(name) {
      try {
        value = require(name);
        return false;
      } catch (error) {
        return true;
      }
    });

    return value;
  };

  handler.get = function(target, property, receiver) {
    if (target.hasOwnProperty(property)) {
      return target[property];
    }

    const names = getNames(property);
    target[property] = getRequire(names);

    if (null !== target[property]) {
      return target[property];
    }

    delete target[property];
    const error = new Error("Cannot find module '" + property + "'");
    error.code = 'MODULE_NOT_FOUND';
    throw error;
  };

  setOptions(options);
  return new Proxy(target, handler);
};<commit_msg>use instanceof to check object<commit_after>'use strict';

module.exports = function(options) {
  let target = {};
  let handler = {};

  let useOptions = {
    mapping: {}, guessName: function(name) {
      return '';
    }
  };

  let setMapping = function(items) {
    if (false === (items instanceof Object)) {
      return;
    }

    Object.keys(items).every(function(index) {
      let item = items[index];

      switch (typeof item) {
        case 'string':
          useOptions.mapping[index] = item;
          break;

        case 'object':
        case 'function':
          target[index] = item;
          break;

        default:
          break;
      }
    });
  };

  let setOptions = function(items) {
    if (false === (items instanceof Object)) {
      return;
    }

    if (items.hasOwnProperty('guessName') && ('function' === typeof items.guessName)) {
      useOptions.guessName = items.guessName;
    }

    if (items.hasOwnProperty('mapping')) {
      setMapping(items.mapping);
    }
  };

  let packageName = function(property) {
    return property.trim().replace(/([a-z\d])([A-Z]+)/g, '$1-$2').replace(/[-\s]+/g, '-').toLowerCase();
  };

  let getNames = function(property) {
    let mapping = useOptions.mapping;
    let names = [];

    if (mapping.hasOwnProperty(property)) {
      names.push(mapping[property]);
    }

    names.push(property);
    names.push(packageName(property));

    try {
      let guessName = useOptions.guessName(property);

      if (('string' === typeof guessName) && ('' !== guessName)) {
        names.push(guessName);
      }

      return names;
    } catch (error) {
      return names;
    }
  };

  let getRequire = function(property) {
    let value = null;

    getNames(property).every(function(name) {
      try {
        value = require(name);
        return false;
      } catch (error) {
        return true;
      }
    });

    return value;
  };

  handler.get = function(target, property) {
    if (target.hasOwnProperty(property)) {
      return target[property];
    }

    target[property] = getRequire(property);

    if (null !== target[property]) {
      return target[property];
    }

    delete target[property];
    let error = new Error("Cannot find module '" + property + "'");
    error.code = 'MODULE_NOT_FOUND';
    throw error;
  };

  setOptions(options);
  return new Proxy(target, handler);
};
{'fraction_non_alphanumeric': 0.15254590984974958, 'fraction_numerical': 0.0008347245409015025, 'mean_word_length': 2.3848870056497176, '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': '1802609', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1438, 'n_words': 306}