<commit_before>import { find } from './utils';

export default class FieldBag {
  constructor() {
    this.items = [];
  }

  /**
   * Finds the first field that matches the provided matcher object.
   * @param {Object} matcher
   */
  find(matcher) {
    return find(this.items, item => item.matches(matcher));
  }

  /**
   * Finds and removes the first field that matches the provided matcher object.
   * @param {Object} matcher
   */
  remove(matcher) {
    const item = this.find(matcher);
    if (!item) return;

    const index = this.items.indexOf(item);
    if (index === -1) return;

    this.items.splice(index, 1);
  }
}
<commit_msg>add filter method<commit_after>import { find } from './utils';

export default class FieldBag {
  constructor () {
    this.items = [];
  }

  /**
   * Finds the first field that matches the provided matcher object.
   * @param {Object} matcher
   */
  find (matcher) {
    return find(this.items, item => item.matches(matcher));
  }

  /**
   * @param {Object} matcher 
   */
  filter (matcher) {
    return this.items.filter(item => item.matches(matcher));
  }

  /**
   * Finds and removes the first field that matches the provided matcher object.
   * @param {Object} matcher
   */
  remove (matcher) {
    const item = this.find(matcher);
    if (!item) return;

    const index = this.items.indexOf(item);
    if (index === -1) return;

    this.items.splice(index, 1);
  }

  push (item) {
    this.items.push(item);
  }
}
{'fraction_non_alphanumeric': 0.1423728813559322, 'fraction_numerical': 0.002711864406779661, 'mean_word_length': 2.7653061224489797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5063111', 'n_tokens_mistral': 492, 'n_tokens_neox': 476, 'n_words': 133}