<commit_before>'use strict';

var cssauron = require('cssauron');

function isString(thing) {
  return typeof thing === 'string';
}

function isArray(thing) {
  return Object.prototype.toString.call(thing) === '[object Array]';
}
var language = cssauron({
  tag: 'tag',
  contents: function(node) {
    if (isString(node)) {
      return node;
    }
    return isString(node.children) ? node.children : '';
  },
  id: function(node) {
    if (node.attrs) {
      return node.attrs.id;
    }
    return '';
  },
  class: function(node) {
    if (node.attrs) {
      return node.attrs.className;
    }
    return '';
  },
  parent: 'parent',
  children: function(node) {
    return node.children;
  },
  attr: function(node, attr) {
    if (node.attrs) {
      return node.attrs[attr];
    }
  }
});

function parse(rootEl) {
  function find(selector, subEl) {
    selector = isString(selector) ? language(selector) : selector;
    var el = subEl || rootEl;
    var els = isArray(el) ? el : [el];
    els = els.filter(function(el) { return el !== undefined });
    var foundEls = els.reduce(function(foundEls, el) {
      if (selector(el)) {
        foundEls.push(el);
      }
      if (isArray(el)) {
        return foundEls.concat(find(selector, el));
      }
      // sometimes mithril spits out an array with only one undefined.
      // The following if should catch that
      if (isString(el.children) || !el.children || (el.children.length && !el.children[0])) {
        return foundEls;
      }
      el.children.filter(function(child) { return typeof child === 'object' }).forEach(function(child) {
        child.parent = el;
      });
      return foundEls.concat(find(selector, el.children));
    }, []);
    return foundEls;
  }
  function first(selector) {
    return find(selector)[0];
  }
  function has(selector) {
    return find(selector).length > 0;
  }
  function contains(string, subEl) {
    var el = subEl || rootEl;
    var els = isArray(el) ? el : [el];
    return els.some(function(el) {
      if (isString(el)) {
        return el.indexOf(string) >= 0;
      }
      if (isString(el.children)) {
        return el.children.indexOf(string) >= 0;
      }
      if (el.children && el.children.children) {
        return contains(string, el.children);
      }
      if (el.children) {
        return el.children.some(function(el) {
          return contains(string, el);
        });
      }
    });
  }

  function setValue(selector, string) {
    var attrs = first(selector).attrs;
    (attrs.oninput || attrs.onchange || attrs.onkeyup)({
      currentTarget: {value: string}
    });
  }

  function click(selector, event) {
    var attrs = first(selector).attrs;
    attrs.onclick(event);
  }

  function focus(selector, event) {
    var attrs = first(selector).attrs;
    attrs.onfocus(event);
  }

  return {
    find: find,
    first: first,
    has: has,
    contains: contains,
    setValue: setValue,
    click: click,
    focus: focus<commit_msg>Add blur method<commit_after>'use strict';

var cssauron = require('cssauron');

function isString(thing) {
  return typeof thing === 'string';
}

function isArray(thing) {
  return Object.prototype.toString.call(thing) === '[object Array]';
}
var language = cssauron({
  tag: 'tag',
  contents: function(node) {
    if (isString(node)) {
      return node;
    }
    return isString(node.children) ? node.children : '';
  },
  id: function(node) {
    if (node.attrs) {
      return node.attrs.id;
    }
    return '';
  },
  class: function(node) {
    if (node.attrs) {
      return node.attrs.className;
    }
    return '';
  },
  parent: 'parent',
  children: function(node) {
    return node.children;
  },
  attr: function(node, attr) {
    if (node.attrs) {
      return node.attrs[attr];
    }
  }
});

function parse(rootEl) {
  function find(selector, subEl) {
    selector = isString(selector) ? language(selector) : selector;
    var el = subEl || rootEl;
    var els = isArray(el) ? el : [el];
    els = els.filter(function(el) { return el !== undefined });
    var foundEls = els.reduce(function(foundEls, el) {
      if (selector(el)) {
        foundEls.push(el);
      }
      if (isArray(el)) {
        return foundEls.concat(find(selector, el));
      }
      // sometimes mithril spits out an array with only one undefined.
      // The following if should catch that
      if (isString(el.children) || !el.children || (el.children.length && !el.children[0])) {
        return foundEls;
      }
      el.children.filter(function(child) { return typeof child === 'object' }).forEach(function(child) {
        child.parent = el;
      });
      return foundEls.concat(find(selector, el.children));
    }, []);
    return foundEls;
  }
  function first(selector) {
    return find(selector)[0];
  }
  function has(selector) {
    return find(selector).length > 0;
  }
  function contains(string, subEl) {
    var el = subEl || rootEl;
    var els = isArray(el) ? el : [el];
    return els.some(function(el) {
      if (isString(el)) {
        return el.indexOf(string) >= 0;
      }
      if (isString(el.children)) {
        return el.children.indexOf(string) >= 0;
      }
      if (el.children && el.children.children) {
        return contains(string, el.children);
      }
      if (el.children) {
        return el.children.some(function(el) {
          return contains(string, el);
        });
      }
    });
  }

  function setValue(selector, string) {
    var attrs = first(selector).attrs;
    (attrs.oninput || attrs.onchange || attrs.onkeyup)({
      currentTarget: {value: string}
    });
  }

  function click(selector, event) {
    var attrs = first(selector).attrs;
    attrs.onclick(event);
  }

  function focus(selector, event) {
    var attrs = first(selector).attrs;
    attrs.onfocus(event);
  }

  function blur(selector, event) {
    var attrs = first(selector).attrs;
    attrs.onblur(event);
  }

  return {
    find: find,
    first: first,
    has: has,
    contains: contains,
    setValue: setValue,
    click: click,
    focus: focus,
    blur: blur
{'fraction_non_alphanumeric': 0.1477946017116524, 'fraction_numerical': 0.0016458196181698486, 'mean_word_length': 2.6086698337292162, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1899888', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1968, 'n_words': 442}