<commit_before>'use strict';

var set = require('lodash.set');

update.with = updateWith;
updateIn.with = updateInWith;
update.in = updateIn;

module.exports = update;

function updateInWith(obj, name, fn) {
  _update(obj, name, fn);

  return obj;
}

function updateIn(obj, name, value) {
  return updateInWith(obj, name, function(){ return value });
}

function update(obj, name, value) {
  return updateWith(obj, name, function(){ return value });
}

function updateWith(obj, name, fn) {
  var current = shallowCopy(obj);

  return updateInWith(current, name, fn);
}

function _update(current, name, fn) {
  var match = name.match(/^([{\w\d:_-}]+)\.?(.+)?$/);
  var key = match[1], rest = match[2];

  if (isLookupKey(key)) {
    if (!Array.isArray(current)) {
      throw new Error('object lookup available only for existing collections');
    }
    var lookupKey = key;
    key = lookupIndex(current, key);
    if (key === undefined) {
      throw new Error(`no object found by ${lookupKey}. autocreate is not supported`);
    } 
  }

  if (current[key] === undefined) {
    if (isLookupKey(rest)) {
      throw new Error('autocreate with lookup path is not supported');
    }
    return set(current, name.split('.'), fn());
  }
  if (!rest) {<commit_msg>fix message interpolation when throwing lookup error<commit_after>'use strict';

var set = require('lodash.set');

update.with = updateWith;
updateIn.with = updateInWith;
update.in = updateIn;

module.exports = update;

function updateInWith(obj, name, fn) {
  _update(obj, name, fn);

  return obj;
}

function updateIn(obj, name, value) {
  return updateInWith(obj, name, function(){ return value });
}

function update(obj, name, value) {
  return updateWith(obj, name, function(){ return value });
}

function updateWith(obj, name, fn) {
  var current = shallowCopy(obj);

  return updateInWith(current, name, fn);
}

function _update(current, name, fn) {
  var match = name.match(/^([{\w\d:_-}]+)\.?(.+)?$/);
  var key = match[1], rest = match[2];

  if (isLookupKey(key)) {
    if (!Array.isArray(current)) {
      throw new Error('object lookup available only for existing collections');
    }
    var lookupKey = key;
    key = lookupIndex(current, key);
    if (key === undefined) {
      throw new Error('no object found by ' + lookupKey + '. autocreate is not supported');
    }
  }

  if (current[key] === undefined) {
    if (isLookupKey(rest)) {
      throw new Error('autocreate with lookup path is not supported');
    }
    return set(current, name.split('.'), fn());
  }
  if (!rest) {
{'fraction_non_alphanumeric': 0.15801794771751854, 'fraction_numerical': 0.0015606710885680843, 'mean_word_length': 3.783582089552239, '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': '7257735', 'n_tokens_mistral': 831, 'n_tokens_neox': 815, 'n_words': 242}