<commit_before>var _ = require('lodash');
var path = require('path');
var extend = require('deep-extend');

function Config(opts) {}

function _getCallerFile() {
  try {
    var err = new Error();
    var callerfile;
    var currentfile;

    Error.prepareStackTrace = function (err, stack) { return stack; };
    currentfile = err.stack.shift().getFileName();

    while (err.stack.length) {
      callerfile = err.stack.shift().getFileName();
      if(currentfile !== callerfile) return callerfile;
    }
  } catch (err) {}
  return undefined;
}

Config.prototype.set = function (opts, val) {
  if (typeof opts === 'object') {
    extend(this, opts);
  } else if (typeof opts === 'function') {
    extend(this, module(this));
  } else if (typeof opts === 'string') {
    try {
      var callerFile = _getCallerFile();
      var moduleFile = path.join(path.dirname(callerFile), opts);
      var module = require(moduleFile);
      this.set(module)
    } catch (e) {
      console.log(e)
    }
  }
}

Config.prototype.get = function (key) {
  return _.get(this, key);
}

Config.prototype.Config = Config;

module.exports = new Config();<commit_msg>Added test for set by function, and fixed it<commit_after>var _ = require('lodash');
var path = require('path');
var extend = require('deep-extend');

function Config(opts) {}

function _getCallerFile() {
  try {
    var err = new Error();
    var callerfile;
    var currentfile;

    Error.prepareStackTrace = function (err, stack) { return stack; };
    currentfile = err.stack.shift().getFileName();

    while (err.stack.length) {
      callerfile = err.stack.shift().getFileName();
      if(currentfile !== callerfile) return callerfile;
    }
  } catch (err) {}
  return undefined;
}

Config.prototype.set = function (opts, val) {
  if (typeof opts === 'object') {
    extend(this, opts);
  } else if (typeof opts === 'function') {
    extend(this, opts(this));
  } else if (typeof opts === 'string') {
    try {
      var callerFile = _getCallerFile();
      var moduleFile = path.join(path.dirname(callerFile), opts);
      var module = require(moduleFile);
      this.set(module)
    } catch (e) {
      console.log(e)
    }
  }
}

Config.prototype.get = function (key) {
  return _.get(this, key);
}

Config.prototype.Config = Config;

module.exports = new Config();
{'fraction_non_alphanumeric': 0.15268817204301074, 'fraction_numerical': 0.0, 'mean_word_length': 3.283609576427256, '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': '7495575', 'n_tokens_mistral': 730, 'n_tokens_neox': 725, 'n_words': 185}