<commit_before>var monkey = (function() {
  var invokeHooks = function(list, context, arguments) {
    for(var i=0,l=list.length;i<l;i++) {
      list[i].apply(context, arguments);
    }
  }
  
  var handleFn = function wrap(fn, target) {
    var befores = [], afters = [], returnTarget = false, wrappedFn;
    wrappedFn = function wrapper() {
      invokeHooks(befores, this, arguments);
      var actualReturn = fn.apply(this, arguments);
      invokeHooks(afters, this, arguments);
      return actualReturn;
    };
    
    if(!target) {
      returnTarget = true;
      target = function() { return wrappedFn.apply(this, arguments) };
    }
    
    target.before = function(fn) { befores.push(fn); return target; };
    target.after = function(fn) { afters.push(fn); return target; };
    target.done = function() { return wrappedFn; };
    
    return returnTarget ? target : wrappedFn;
  }
  
  var handleObj = function(ctx, prop) {
    var helper = {};
    ctx[prop] = handleFn(ctx[prop], helper)
    return helper;    
  };
  
  
  return function monkeyPatch() {
    var fn, apply = Function.prototype.apply;
    
    // monkey(fn)
    if(arguments.length == 1 && arguments[0].apply == apply) {
      return handleFn.apply(this, arguments);
    }
    
    // monkey(object, property)
    if(arguments.length == 2 && arguments[0][arguments[1]].apply == apply) {
      return handleObj.apply(this, arguments);
    }
    
    throw "Invalid arguments";
  };
}());<commit_msg>Added support for transforming the return value<commit_after>var monkey = (function() {
  
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Polyfill
  var reduce = Array.prototype.reduce || function(callback, opt_initialValue){
    'use strict';
    if (null === this || 'undefined' === typeof this) {
      throw new TypeError('Array.prototype.reduce called on null or undefined');
    }
    if ('function' !== typeof callback) {
      throw new TypeError(callback + ' is not a function');
    }
    var index, value, length = this.length >>> 0, isValueSet = false;
    if (1 < arguments.length) {
      value = opt_initialValue;
      isValueSet = true;
    }
    for (index = 0; length > index; ++index) {
      if (this.hasOwnProperty(index)) {
        if (isValueSet) {
          value = callback(value, this[index], index, this);
        }
        else {
          value = this[index];
          isValueSet = true;
        }
      }
    }
    if (!isValueSet) {
      throw new TypeError('Reduce of empty array with no initial value');
    }
    return value;
  };

  var invokeHooks = function(list, context, arguments) {
    for(var i=0,l=list.length;i<l;i++) {
      list[i].apply(context, arguments);
    }
  }
  
  var handleFn = function wrap(fn, target) {
    var befores = [], afters = [], trs = [], returnTarget = false, wrappedFn;
    wrappedFn = function wrapper() {
      invokeHooks(befores, this, arguments);
      var actualReturn = fn.apply(this, arguments);
      invokeHooks(afters, this, arguments);
      return reduce.call(trs, function(val,fn) { return fn(val); }, actualReturn);
    };
    
    if(!target) {
      returnTarget = true;
      target = function() { return wrappedFn.apply(this, arguments) };
    }
    
    target.before = function(fn) { befores.push(fn); return target; };
    target.after = function(fn) { afters.push(fn); return target; };
    target.tr = function(fn) { trs.push(fn); return target; };
    target.done = function() { return wrappedFn; };
    
    return returnTarget ? target : wrappedFn;
  }
  
  var handleObj = function(ctx, prop) {
    var helper = {};
    ctx[prop] = handleFn(ctx[prop], helper)
    return helper;    
  };
  
  
  return function monkeyPatch() {
    var fn, apply = Function.prototype.apply;
    
    // monkey(fn)
    if(arguments.length == 1 && arguments[0].apply == apply) {
      return handleFn.apply(this, arguments);
    }
    
    // monkey(object, property)
    if(arguments.length == 2 && arguments[0][arguments[1]].apply == apply) {
      return handleObj.apply(this, arguments);
    }
    
    throw new TypeError("Invalid arguments");
  };
}());
{'fraction_non_alphanumeric': 0.1433700335088559, 'fraction_numerical': 0.0035902345619913834, 'mean_word_length': 2.7750677506775068, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 1, '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': '4251952', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1274, 'n_words': 303}