<commit_before>/* global define */
void (function (root, factory) {
  if (typeof define === 'function' && define.amd) define(factory)
  else if (typeof exports === 'object') module.exports = factory()
  else root.unorphan = factory()
}(this, function () {

  var TEXT = 3
  var ELEMENT = 1
  var nbsp = '\xA0'

  unorphan.eachTextNode = eachTextNode
  return unorphan

  function unorphan (n) {
    if (!n) return
    if (typeof n === 'string') { /* string */
      unorphan(document.querySelectorAll(n))
    } else if (n.nodeType === ELEMENT) { /* element */
      unorphanElement(n)
    } else if (n.nodeType === TEXT) { /* text node */
      n.nodeValue = n.nodeValue.replace(/\s+([^\s]*)\s*$/, nbsp + '$1')
    } else if (n.length) { /* node list or jQuery object */
      for (var i = 0, len = n.length; i < len; i++) {
        unorphan(n[i])
      }
    }
  }

  /*
   * Recursively checks text nodes in an element and replaces the first
   * eligible space it encounters to a non-breaking space.
   */

  function unorphanElement (node) {
    // keep track if we've seen a non-space character yet.
    var dirty

    eachTextNode(node, function (n) {
      var text = n.nodeValue

      if (!dirty && /^\s*$/.test(text)) {
        // "  "  => pass
      } else if (!dirty && /\s+[^\s]+\s*$/.test(text)) {
        // " xx" or " xx " => "_xx" (done!)
        n.nodeValue = text.replace(/\s+([^\s]+)\s*$/, nbsp + '$1')
        return false<commit_msg>Clarify comments again<commit_after>/* global define */
void (function (root, factory) {
  if (typeof define === 'function' && define.amd) define(factory)
  else if (typeof exports === 'object') module.exports = factory()
  else root.unorphan = factory()
}(this, function () {

  var TEXT = 3
  var ELEMENT = 1
  var nbsp = '\xA0'

  unorphan.eachTextNode = eachTextNode
  return unorphan

  function unorphan (n) {
    if (!n) return
    if (typeof n === 'string') { /* selector string */
      unorphan(document.querySelectorAll(n))
    } else if (n.nodeType === ELEMENT) {
      unorphanElement(n)
    } else if (n.nodeType === TEXT) {
      n.nodeValue = n.nodeValue.replace(/\s+([^\s]*)\s*$/, nbsp + '$1')
    } else if (n.length) { /* node list or jQuery object */
      for (var i = 0, len = n.length; i < len; i++) { unorphan(n[i]) }
    }
  }

  /*
   * Recursively checks text nodes in an element and replaces the first
   * eligible space it encounters to a non-breaking space.
   */

  function unorphanElement (node) {
    // keep track if we've seen a non-space character yet.
    var dirty

    eachTextNode(node, function (n) {
      var text = n.nodeValue

      if (!dirty && /^\s*$/.test(text)) {
        // "  "  => pass
      } else if (!dirty && /\s+[^\s]+\s*$/.test(text)) {
        // " xx" or " xx " => "_xx" (done!)
        n.nodeValue = text.replace(/\s+([^\s]+)\s*$/, nbsp + '$1')
        return false
{'fraction_non_alphanumeric': 0.17614424410540916, 'fraction_numerical': 0.004160887656033287, 'mean_word_length': 2.4386174016686533, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '386683', 'n_tokens_mistral': 1011, 'n_tokens_neox': 982, 'n_words': 283}