<commit_before>'use strict';

/*
 * Outputs objs into key="value" string
 */
module.exports = function attributes(obj) {
  if (!obj) return '';

  let str = '';

  Object.keys(obj).forEach((key) => {
    if (obj[key] && !(obj[key] instanceof Function)) {
      str += ` ${key}="${obj[key]}"`;
    }
  });

  return str;
};<commit_msg>Allow class attribute to be an object<commit_after>'use strict';

// copied from preact/src/dom/index.js 20161103
function hashToClassName(c) {
  let str = '';

  // eslint-disable-next-line
  for (let prop in c) {
    if (c[prop]) {
      if (str) str += ' ';

      str += prop;
    }
  }

  return str;
}

/*
 * Outputs objs into key="value" string
 */
module.exports = function attributes(obj) {
  if (!obj) return '';

  let str = '';

  Object.keys(obj).forEach((key) => {
    let value = obj[key];

    if (value && !(value instanceof Function)) {
      if (key === 'className') key = 'class';

      if (key === 'class') {
        if (Array.isArray(value)) {
          value = value.filter((value) => value).join(' ');
        } else if (typeof value === 'object') {
          value = hashToClassName(value);
        }
      }

      str += ` ${key}="${value}"`;
    }
  });

  return str;
};
{'fraction_non_alphanumeric': 0.19448946515397084, 'fraction_numerical': 0.006482982171799027, 'mean_word_length': 2.5185185185185186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6679417', 'n_tokens_mistral': 427, 'n_tokens_neox': 411, 'n_words': 102}