<commit_before>clone = require 'clone'

module.exports = ($) ->

  isNode = $.isNode = (node) ->
    return node? and (typeof node is 'object') and !(node instanceof Array)

  $.append = (parent,child) ->
    return parent unless isNode parent
    parent.children = [] unless parent.children?
    parent.children.push child

  $.prepend = (parent,child) ->
    return parent unless isNode parent
    parent.children = [] unless parent.children?
    parent.children.splice 0, 0, child

  $.addClass = (node,names) ->
    node.attributes = {} unless node.attributes?
    node.attributes.class = [] unless node.attributes.class?
    return _addClass(node,names) unless names instanceof Array
    for name in names
      _addClass(node,name)
    node

  _addClass = (node,name) ->
    return node unless isNode node
    classes = node.attributes.class
    classes.push(name) if classes.indexOf(name) is -1
    classes

  $.removeClass = (node,names) ->
    return node unless node.attributes?
    return node unless node.attributes.class?
    return _addClass(node,names) unless names instanceof Array
    for name in names
      _removeClass(node,name)
    node

  _removeClass = (node, name) ->
    return node unless isNode node
    classes = node.attributes.class
    i = classes.indexOf(name)
    classes.splice(i,1) if i isnt -1
    classes

  $.hasClass = (node,names) ->
    return false unless node.attributes?
    return false unless node.attributes.class?
    return _hasClass(node,names) unless names instanceof Array
    for name in names
      boolean = _hasClass(node,name)
      return boolean unless boolean
    true

  _hasClass = (node,name) ->
    return node.attributes.class.indexOf(name) isnt -1

  $.getChildren = (node, childTagNames) ->
    if node.children instanceof Array
      for tagName in childTagNames
        for child in node.children
          return child if child.tag is tagName

      for child in node.children
        foundChild = $.getChildren(child, childTagNames)
        return foundChild if foundChild

    return null

  $.setAttribute = (node,key,val) ->
    return node unless isNode(node)<commit_msg>fix undefined child<commit_after>clone = require 'clone'

module.exports = ($) ->

  isNode = $.isNode = (node) ->
    return node? and (typeof node is 'object') and !(node instanceof Array)

  $.append = (parent,child) ->
    return parent unless isNode parent
    parent.children = [] unless parent.children?
    parent.children.push child

  $.prepend = (parent,child) ->
    return parent unless isNode parent
    parent.children = [] unless parent.children?
    parent.children.splice 0, 0, child

  $.addClass = (node,names) ->
    node.attributes = {} unless node.attributes?
    node.attributes.class = [] unless node.attributes.class?
    return _addClass(node,names) unless names instanceof Array
    for name in names
      _addClass(node,name)
    node

  _addClass = (node,name) ->
    return node unless isNode node
    classes = node.attributes.class
    classes.push(name) if classes.indexOf(name) is -1
    classes

  $.removeClass = (node,names) ->
    return node unless node.attributes?
    return node unless node.attributes.class?
    return _addClass(node,names) unless names instanceof Array
    for name in names
      _removeClass(node,name)
    node

  _removeClass = (node, name) ->
    return node unless isNode node
    classes = node.attributes.class
    i = classes.indexOf(name)
    classes.splice(i,1) if i isnt -1
    classes

  $.hasClass = (node,names) ->
    return false unless node.attributes?
    return false unless node.attributes.class?
    return _hasClass(node,names) unless names instanceof Array
    for name in names
      boolean = _hasClass(node,name)
      return boolean unless boolean
    true

  _hasClass = (node,name) ->
    return node.attributes.class.indexOf(name) isnt -1

  $.getChildren = (node, childTagNames) ->
    if node? and node.children instanceof Array
      for tagName in childTagNames
        for child in node.children
          return child if child? and child.tag is tagName

      for child in node.children
        foundChild = $.getChildren(child, childTagNames)
        return foundChild if foundChild

    return null

  $.setAttribute = (node,key,val) ->
    return node unless isNode(node)
{'fraction_non_alphanumeric': 0.09534829900485998, 'fraction_numerical': 0.00277713492247165, 'mean_word_length': 2.998149861239593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '5184692', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1199, 'n_words': 389}