<commit_before>'use strict';
var eql = require('deep-eql');

function find(array, predicate) {
  var length = array.length;
  for (var i = 0; i < length; i++) {
    var value = array[i];
    if (predicate(value)) return value;
  }
}

function findHandler(handlers, method, url, body) {
  return find(handlers[method.toLowerCase()], function(handler) {
    if (typeof handler[0] === 'string') {
      return url === handler[0] && isBodyMatching(body, handler[4]);
    } else if (handler[0] instanceof RegExp) {
      return handler[0].test(url) && isBodyMatching(body, handler[4]);
    }
  });
}

function isBodyMatching(body, requiredBody) {
  var parsedBody;
  var isJSON = true;
  try {
    parsedBody = JSON.parse(body);
  } catch (error) {
    isJSON = false;
  }
  return requiredBody === undefined
    || (typeof body === 'string' && body === requiredBody || eql(body, requiredBody)
    || (isJSON && eql(parsedBody, requiredBody)));
}

function purgeIfReplyOnce(mock, handler) {
  var index = mock.replyOnceHandlers.indexOf(handler);
  if (index > -1) {
    mock.replyOnceHandlers.splice(index, 1);<commit_msg>improved isBodyMatching function<commit_after>'use strict';
var eql = require('deep-eql');

function find(array, predicate) {
  var length = array.length;
  for (var i = 0; i < length; i++) {
    var value = array[i];
    if (predicate(value)) return value;
  }
}

function findHandler(handlers, method, url, body) {
  return find(handlers[method.toLowerCase()], function(handler) {
    if (typeof handler[0] === 'string') {
      return url === handler[0] && isBodyMatching(body, handler[4]);
    } else if (handler[0] instanceof RegExp) {
      return handler[0].test(url) && isBodyMatching(body, handler[4]);
    }
  });
}

function isBodyMatching(body, requiredBody) {
  if (requiredBody === undefined) {
    return true;
  }
  var parsedBody;
  try {
    parsedBody = JSON.parse(body);
  } catch (e) { }
  return parsedBody ? eql(parsedBody, requiredBody) : eql(body, requiredBody);
}

function purgeIfReplyOnce(mock, handler) {
  var index = mock.replyOnceHandlers.indexOf(handler);
  if (index > -1) {
    mock.replyOnceHandlers.splice(index, 1);
{'fraction_non_alphanumeric': 0.1543778801843318, 'fraction_numerical': 0.008294930875576038, 'mean_word_length': 4.0606060606060606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2039699', 'n_tokens_mistral': 722, 'n_tokens_neox': 720, 'n_words': 174}