<commit_before>import runtime from '../../../core/runtime.js'

// basic element utils for convenience inspired by jquery API

var elementStringRegex = /^<(\S+)>$/i

// main

var el = function (x, attributes) {
  runtime.assertBrowser()

  if (x) {
    if (typeof x === 'string') {
      // create element
      var tagSearch = elementStringRegex.exec(x)
      var tag = tagSearch ? tagSearch[1] : null
      if (tag) {
        return addElement(tag, attributes)
      } else {
        throw 'Only basic tags like "<div>" without attributes are currently supported. (No queries and no HTML strings)'
      }
    } else if (isElement(x)) {
      // only add convenience methods
      extendWithConvenienceMethods(x)
    } else {
      throw 'Please provide html element string (i.e. "<div>") or element object as first argument.'
    }
  }
}

// utils
el.isElement = isElement

export default el

// helpers

function addElement (type, attrs) {
  runtime.assertBrowser()

  // create element
  var el = document.createElement(type)

  // add attributes
  if (attrs) Object.keys(attrs).forEach(function (key) {
    if (key === 'text') {
      // text
      el.appendChild(document.createTextNode(attrs.text))
    } else if (key === 'html') {
      // html
      el.innerHTML = attrs.html
    } else if (key === 'click' || key === 'keydown' || key === 'keyup') {
      // events
      el.addEventListener(key, attrs[key])
    } else {
      // any other attributes
      el.setAttribute(key, attrs[key])
    }
  })

  extendWithConvenienceMethods(el)

  return el
}

function extendWithConvenienceMethods (el) {
  el.remove = function removeElement (child) {
    child ? el.removeChild(child) : el.parentNode.removeChild(el)
    return el
  }
  el.append = function append (o) {
    if (o) isElement(o) ? el.appendChild(o) : el.innerHTML = o
    return el
  }
  el.appendTo = function appendToElement (parentEl) {
    parentEl === 'body' ? document.body.appendChild(el) : parentEl.appendChild(el)
    return el<commit_msg>adds el.empty method<commit_after>import runtime from '../../../core/runtime.js'

// basic element utils for convenience inspired by jquery API

var elementStringRegex = /^<(\S+)>$/i

// main

var el = function (x, attributes) {
  runtime.assertBrowser()

  if (x) {
    if (typeof x === 'string') {
      // create element
      var tagSearch = elementStringRegex.exec(x)
      var tag = tagSearch ? tagSearch[1] : null
      if (tag) {
        return addElement(tag, attributes)
      } else {
        throw 'Only basic tags like "<div>" without attributes are currently supported. (No queries and no HTML strings)'
      }
    } else if (isElement(x)) {
      // only add convenience methods
      extendWithConvenienceMethods(x)
    } else {
      throw 'Please provide html element string (i.e. "<div>") or element object as first argument.'
    }
  }
}

// utils
el.isElement = isElement

export default el

// helpers

function addElement (type, attrs) {
  runtime.assertBrowser()

  // create element
  var el = document.createElement(type)

  // add attributes
  if (attrs) Object.keys(attrs).forEach(function (key) {
    if (key === 'text') {
      // text
      el.appendChild(document.createTextNode(attrs.text))
    } else if (key === 'html') {
      // html
      el.innerHTML = attrs.html
    } else if (key === 'click' || key === 'keydown' || key === 'keyup') {
      // events
      el.addEventListener(key, attrs[key])
    } else {
      // any other attributes
      el.setAttribute(key, attrs[key])
    }
  })

  extendWithConvenienceMethods(el)

  return el
}

function extendWithConvenienceMethods (el) {
  el.remove = function removeElement (child) {
    child ? el.removeChild(child) : el.parentNode.removeChild(el)
    return el
  }
  el.empty = function emptyElement () {
    while (el.lastChild) el.removeChild(el.lastChild)
    return el
  }
  el.append = function append (o) {
    if (o) isElement(o) ? el.appendChild(o) : el.innerHTML = o
    return el
  }
  el.appendTo = function appendToElement (parentEl) {
    parentEl === 'body' ? document.body.appendChild(el) : parentEl.appendChild(el)
    return el
{'fraction_non_alphanumeric': 0.13237063778580024, 'fraction_numerical': 0.0004813477737665463, 'mean_word_length': 2.7644927536231885, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2736529', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1270, 'n_words': 357}