<commit_before>const DIGIT_REGEX = /^\d+$/
const readableIdPartFromWord = word => DIGIT_REGEX.test(word) ? word : word[0]
function prepareName(rawName) {
  const name = rawName.trim().toLowerCase().replace(/[^\w\d]/g, ' ').replace(/\s/g, '_')
  return name.slice(name.search(/[^\d]/))
}

function getDirectVariableNameFromName(rawName, maxOneWordLength, maxSplitWordLength) {
  const name = prepareName(rawName)

  const words = name.split(/[\_]/).filter(s => !_.isEmpty(s))

  if (words.length === 1 && name.length < maxOneWordLength) {
    return name
  } else if (words.length < maxSplitWordLength) {
    return name.slice(0, maxSplitWordLength)
  } else {
    return words.map(readableIdPartFromWord).join('')
  }
}

export function getVariableNameFromName(rawName, existingVariableNames=[], maxOneWordLength=30, maxSplitWordLength=8) {
  const directName = getDirectVariableNameFromName(rawName, maxOneWordLength, maxSplitWordLength)
<commit_msg>Further refinements to the name to variable name transition process.<commit_after>const DIGIT_REGEX = /^\d+$/
const readableIdPartFromWord = word => DIGIT_REGEX.test(word) ? word : word[0]
function prepareName(rawName) {
  const name = rawName.trim().toLowerCase().replace(/[^\w\d]/g, ' ')
  const firstNonDigit = name.search(/[^\d]/)
  if (firstNonDigit === -1) { return '' }
  return name.slice(firstNonDigit).trim().replace(/\s/g, '_')
}

function getDirectVariableNameFromName(rawName, maxOneWordLength, maxSplitWordLength) {
  const name = prepareName(rawName)

  const words = name.split(/[\_]/).filter(s => !_.isEmpty(s))

  if (words.length === 1 && name.length < maxOneWordLength) {
    return name
  } else if (words.length < maxSplitWordLength) {
    return name.slice(0, maxSplitWordLength)
  } else {
    return words.map(readableIdPartFromWord).join('')
  }
}

export function getVariableNameFromName(rawName, existingVariableNames=[], maxOneWordLength=30, maxSplitWordLength=8) {
  const directName = getDirectVariableNameFromName(rawName, maxOneWordLength, maxSplitWordLength)

{'fraction_non_alphanumeric': 0.14432485322896282, 'fraction_numerical': 0.006360078277886497, 'mean_word_length': 5.253822629969419, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5691788', 'n_tokens_mistral': 674, 'n_tokens_neox': 660, 'n_words': 127}