<commit_before>module.exports = function init (fns, options, stack) {
  options = options || {}
  stack = stack || []
  function api (value) {
    var allMode = options.mode === 'all'
    var exceptionMode = options.mode === 'exception'
    var result = true
    var errors = []
    // in all mode we run through all validators (map),
    // in first/exception mode we stop with the first error (every)
    var walker = allMode ? 'map' : 'every'
    stack[walker](function (fn) {
      var isValid
      try {
        isValid = fn(value)
      } catch (err) {
        if (exceptionMode) {
          throw err
        }
        // not in exception mode, unwrap the exception
        isValid = err instanceof Error ? err.message : err
      }
      if (allMode) {
        // if in all mode, collect the error and continue with the next validator
        if (isValid !== true) {
          errors.push(isValid || 'validation failed')
        }
        return
      }
      result = isValid
      if (typeof isValid === 'boolean') {
        return isValid
      }
      // if anything other than a true or false is returned by the validator
      // we consider that as an error message an stop validating
      return false
    })
    if (exceptionMode) {
      throw new Error(result)
    }
    return allMode ? errors : result
  }
  fns.object = function(schema) {
    return function(obj) {<commit_msg>Refactor<commit_after>function validate(value, mode) {
  var allMode = mode === 'all'
  var exceptionMode = mode === 'exception'
  return function (result, fn) {
    if (!allMode && result !== true) {
      return result
    }
    var isValid
    try {
      isValid = fn(value)
    } catch (err) {
      if (exceptionMode) {
        throw err
      }
      // not in exception mode, unwrap the exception
      isValid = err instanceof Error ? err.message : err
    }
    if (!allMode) {
      return isValid
    }
    // if in all mode, collect the error and continue with the next validator
    if (isValid !== true) {
      result.push(isValid || 'validation failed')
    }
    return result
  }
}

module.exports = function init (fns, options, stack) {
  options = options || {}
  stack = stack || []
  function api (value) {
    var allMode = options.mode === 'all'
    var exceptionMode = options.mode === 'exception'
    var result = stack.reduce(validate(value, options.mode), allMode ? [] : true)
    if (exceptionMode) {
      throw new Error(result)
    }
    return result
  }
  fns.object = function(schema) {
    return function(obj) {
{'fraction_non_alphanumeric': 0.10862745098039216, 'fraction_numerical': 0.0, 'mean_word_length': 2.241423125794155, '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': '708220', 'n_tokens_mistral': 725, 'n_tokens_neox': 727, 'n_words': 252}