<commit_before>var asn1 = require('asn1');
var assert = require('assert');
var ldapjs = require('ldapjs');

function isObjectClass(type, entry) {
  var objectClass = entry['objectClass'];
  if (objectClass && Array.isArray(objectClass)) {
    return (objectClass.indexOf(type) > -1);
  }
  return (objectClass == type);
}

function isAttrRequested(attr, req) {
  var lower = attr.toLowerCase();
  return (req.attributes.length == 0 || req.attributes.indexOf(lower) !== -1);
}

function ensureAttrRequested(attr, req) {
  if (!isAttrRequested(attr, req)) {
    req.attributes.push(attr.toLowerCase());
  }
}

function forEachFilter (filter, cb) {
  var result = cb(filter);
  if (result != null && result.filters instanceof Array) {
    var children = filter.filters.map(function (item) {
      var result = forEachFilter(item, cb);
      if (result != null) {
        return result;
      }
    });
    result.filters = children;
  }
  return result;
}


/* Get around the limitations of EqualityFilter */

function BinaryEqualityFilter(options) {
  if (typeof (options) === 'object') {
    if (!options.attribute || typeof (options.attribute) !== 'string')
      throw new TypeError('options.attribute (string) required');
    if (!options.value || !(options.value instanceof Buffer))
      throw new TypeError('options.value (Buffer) required');
    this.attribute = options.attribute;
    this.value = options.value;
  } else {
    options = {};
  }
  options.type = ldapjs.FILTER_EQUALITY;
  ldapjs.Filter.call(this, options);

  var self = this;
  this.__defineGetter__('json', function () {
    return {
      type: 'EqualityMatch',
      attribute: self.attribute || undefined,
      value: self.value || undefined
    };
  });<commit_msg>Refine child filter logic in util.forEachFilter<commit_after>var asn1 = require('asn1');
var assert = require('assert');
var ldapjs = require('ldapjs');

function isObjectClass(type, entry) {
  var objectClass = entry['objectClass'];
  if (objectClass && Array.isArray(objectClass)) {
    return (objectClass.indexOf(type) > -1);
  }
  return (objectClass == type);
}

function isAttrRequested(attr, req) {
  var lower = attr.toLowerCase();
  return (req.attributes.length == 0 || req.attributes.indexOf(lower) !== -1);
}

function ensureAttrRequested(attr, req) {
  if (!isAttrRequested(attr, req)) {
    req.attributes.push(attr.toLowerCase());
  }
}

function forEachFilter(input, cb) {
  var result = cb(input);
  if (result != null) {
    if (Array.isArray(result.filters)) {
      // Handle multi-child filters (such as AND/OR)
      result.filters = result.filters.map(function (item) {
        return forEachFilter(item, cb);
      }).filter(function (item) {
        return (item != null);
      });
      if (result.filters.length == 0) {
        result = null;
      }
    } else if (result.filter) {
      // Handle single-child filters (such as NOT)
      result.filter = forEachFilter(result.filter, cb);
      if (result.filter == null) {
        result = null;
      }
    }
  }
  return result;
}


/* Get around the limitations of EqualityFilter */

function BinaryEqualityFilter(options) {
  if (typeof (options) === 'object') {
    if (!options.attribute || typeof (options.attribute) !== 'string')
      throw new TypeError('options.attribute (string) required');
    if (!options.value || !(options.value instanceof Buffer))
      throw new TypeError('options.value (Buffer) required');
    this.attribute = options.attribute;
    this.value = options.value;
  } else {
    options = {};
  }
  options.type = ldapjs.FILTER_EQUALITY;
  ldapjs.Filter.call(this, options);

  var self = this;
  this.__defineGetter__('json', function () {
    return {
      type: 'EqualityMatch',
      attribute: self.attribute || undefined,
      value: self.value || undefined
    };
  });
{'fraction_non_alphanumeric': 0.14683676126008852, 'fraction_numerical': 0.002863837542306691, 'mean_word_length': 3.421173762945915, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4347254', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1163, 'n_words': 283}