{"size": 1124, "ext": "js", "max_stars_repo_path": "src/filters/entropy.meter/pre.filters/dictionary.words.js", "max_stars_repo_name": "anshumanbh/repo-supervisor", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/filters/entropy.meter/pre.filters/dictionary.words.js", "max_issues_repo_name": "anshumanbh/repo-supervisor", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/filters/entropy.meter/pre.filters/dictionary.words.js", "max_forks_repo_name": "anshumanbh/repo-supervisor", "max_forks_repo_forks_event_min_datetime": "2020-02-07T11:59:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-07T11:59:54.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 26.7619047619, "max_line_length": 88, "alphanum_fraction": 0.6503558719}
'use strict';

const dictionary = new Set(require('an-array-of-english-words'));

const requiredPercent = 0.35;

function splitIntoWords(str) {
  // Hyphens, underscores, and numbers
  str = str.replace(/[-_]/g, ' ')
    .replace(/([0-9]+)/g, ' $1 ');

  // camelCase
  str = str.replace(/([A-Z]+?)([A-Z][a-z])/g, '$1 $2')
    .replace(/([a-z])([A-Z])/g, '$1 $2')
    .toLowerCase();

  // Split into parts
  return str.trim().split(/ +/);
}

/**
 * Determine if a string is composed of dictionary words in camelCase or similar formats
 * eg: MY_VARIABLE, myVariable, MyHTMLGenerator, an-identifier-string
 *
 * This reduces the number of variables, classes, and such that appear
 *
 * @param str {string} The input string
 * @returns {boolean} True if it is not composed of words, false if it is
 */
module.exports = function filterCamelCaseWord(str) {
  const words = splitIntoWords(str);

  // Compare against the word list
  const wordCount = words.reduce(
    (acc, word) => acc + (word.length > 2 && dictionary.has(word)),
    0
  );

  const percent = wordCount / words.length;
  return percent < requiredPercent;
};
