<commit_before>module.exports = {
  safe: function (thing, path, otherwise) {
    thing = (thing instanceof Object) ? thing : {};
    var props = path.split('.');
    if (props.length === 1) {
      return thing[props.shift()] || otherwise;
    } else {
      var prop = props.shift();
      return (thing[prop] instanceof Object) ? this.safe(thing[prop], props.join('.'), otherwise) : otherwise || undefined;
    }
  },

  expand: function (obj, path, thing) {
    obj = (obj instanceof Object) ? obj : {};
    var props = path.split('.');
    if (props.length === 1) {
      obj[props.shift()] = thing;
    } else {
      var prop = props.shift();
      if (!obj[prop]) {
        obj[prop] = {};
      }
      this.expand(obj[prop], props.join('.'), thing);
    }
  }
};
<commit_msg>Use typeof so that new-able objects still work<commit_after>module.exports = {
  safe: function (thing, path, otherwise) {
    thing = (typeof thing === 'object') ? thing : {};
    var props = path.split('.');
    if (props.length === 1) {
      return thing[props.shift()] || otherwise;
    } else {
      var prop = props.shift();
      return (typeof thing[prop] === 'object') ? this.safe(thing[prop], props.join('.'), otherwise) : otherwise || undefined;
    }
  },

  expand: function (obj, path, thing) {
    obj = (obj instanceof Object) ? obj : {};
    var props = path.split('.');
    if (props.length === 1) {
      obj[props.shift()] = thing;
    } else {
      var prop = props.shift();
      if (!obj[prop]) {
        obj[prop] = {};
      }
      this.expand(obj[prop], props.join('.'), thing);
    }
  }
};

{'fraction_non_alphanumeric': 0.1922837585563161, 'fraction_numerical': 0.002489110143123833, 'mean_word_length': 2.5496688741721854, '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': '149145', 'n_tokens_mistral': 508, 'n_tokens_neox': 509, 'n_words': 129}