<commit_before>function getContainerNode(selectorOrHTMLElement) {
  if (typeof selectorOrHTMLElement === 'string') {
    return document.querySelector(selectorOrHTMLElement);
  }

  if (!isDomElement(selectorOrHTMLElement)) {
    throw new Error('Container must be `string` or `HTMLElement`');
  }

  return selectorOrHTMLElement;
}

function isDomElement(o) {
  return o instanceof HTMLElement || o && o.nodeType > 0;
}

function renderTemplate({template, templateHelpers, data}) {
  var hogan = require('hogan.js');
  var forEach = require('lodash/collection/forEach');
  var content;

  if (typeof template !== 'string' && typeof template !== 'function') {
    throw new Error('Template must be `string` or `function`');
  }

  if (typeof template === 'function') {
    content = template(data);
  }

  if (typeof template === 'string') {
    // We add all our template helper methods to the template as lambdas. Note
    // that lambdas in Mustache are supposed to accept a second argument of
    // `render` to get the rendered value, not the literal `{{value}}`. But
    // this is currently broken (see
    // https://github.com/twitter/hogan.js/issues/222).
    data.helpers = {};
    forEach(templateHelpers, (method, name) => {
      data.helpers[name] = () => {
        return (value) => {
          return method(hogan.compile(value).render(data));
        };
      };
    });
    content = hogan.compile(template).render(data);
  }

  return content;
}

module.exports = {
  getContainerNode: getContainerNode,
  renderTemplate: renderTemplate
};
<commit_msg>feat: Warn users if we do not override `helpers` in templates<commit_after>function getContainerNode(selectorOrHTMLElement) {
  if (typeof selectorOrHTMLElement === 'string') {
    return document.querySelector(selectorOrHTMLElement);
  }

  if (!isDomElement(selectorOrHTMLElement)) {
    throw new Error('Container must be `string` or `HTMLElement`');
  }

  return selectorOrHTMLElement;
}

function isDomElement(o) {
  return o instanceof HTMLElement || o && o.nodeType > 0;
}

function renderTemplate({template, templateHelpers, data}) {
  var hogan = require('hogan.js');
  var forEach = require('lodash/collection/forEach');
  var content;

  // We add all our template helper methods to the template as lambdas. Note
  // that lambdas in Mustache are supposed to accept a second argument of
  // `render` to get the rendered value, not the literal `{{value}}`. But
  // this is currently broken (see
  // https://github.com/twitter/hogan.js/issues/222).
  function addTemplateHelpersToData(templateData) {
    templateData.helpers = {};
    forEach(templateHelpers, (method, name) => {
      data.helpers[name] = () => {
        return (value) => {
          return method(hogan.compile(value).render(templateData));
        };
      };
    });
  }

  if (typeof template !== 'string' && typeof template !== 'function') {
    throw new Error('Template must be `string` or `function`');
  }

  if (typeof template === 'function') {
    content = template(data);
  }

  if (typeof template === 'string') {
    if (!data.helpers) {
      data = addTemplateHelpersToData(data);
    } else {
      console.warn('TemplateHelpers not included because template data already contained a .helpers key');
    }

    content = hogan.compile(this.props.template).render(data);
  }

  return content;
}

module.exports = {
  getContainerNode: getContainerNode,
  renderTemplate: renderTemplate
};

{'fraction_non_alphanumeric': 0.13052266820675715, 'fraction_numerical': 0.002310135720473578, 'mean_word_length': 3.624833110814419, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '6107636', 'n_tokens_mistral': 1014, 'n_tokens_neox': 1015, 'n_words': 280}