<commit_before>const hasClass = (elem, className) => {
  if (elem.classList) {
    return elem.classList.contains(className);
  } else {
    return !!elem.className.match(new RegExp(`(\\s|^)${className}(\\s|$)`));
  }
};

const addClass = (elem, className) => {
  if (elem.classList) {
    elem.classList.add(className);
  } else if (!hasClass(elem, className)) {
    elem.className += ` ${className}`;
  }
};

const removeClass = (elem, className) => {
  if (elem.classList) {
    elem.classList.remove(className);
  } else if (hasClass(elem, className)) {
    const reg = new RegExp(`(\\s|^)${className}(\\s|$)`);
    elem.className = elem.className.replace(reg, ' ');
  }
};

module.exports = {
  addClass,
  hasClass,
  removeClass
};<commit_msg>now checking if element hasclass this class before adding and removing it<commit_after>const hasClass = (elem, className) => {
  if (elem.classList) {
    return elem.classList.contains(className);
  } else {
    return !!elem.className.match(new RegExp(`(\\s|^)${className}(\\s|$)`));
  }
};

const addClass = (elem, className) => {
  if (elem.classList && !hasClass(elem, className)) {
    elem.classList.add(className);
  } else if (!hasClass(elem, className)) {
    elem.className += ` ${className}`;
  }
};

const removeClass = (elem, className) => {
  if (elem.classList && hasClass(elem, className)) {
    elem.classList.remove(className);
  } else if (hasClass(elem, className)) {
    const reg = new RegExp(`(\\s|^)${className}(\\s|$)`);
    elem.className = elem.className.replace(reg, ' ');
  }
};

module.exports = {
  addClass,
  hasClass,
  removeClass
};
{'fraction_non_alphanumeric': 0.19209388511426806, 'fraction_numerical': 0.0, 'mean_word_length': 3.8795180722891565, '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': '5497147', 'n_tokens_mistral': 532, 'n_tokens_neox': 545, 'n_words': 107}