<commit_before>const multipliers = [2, 3, 4, 5, 6, 7, 2, 3]

exports.verify = function (rut, cb) {
// trim and remove dots and dashes
  rut = rut.toString().trim()
  rut = rut.toLowerCase()
  rut = rut.replace('.', '')
  rut = rut.replace('-', '')

// check if rut only contains numbers
  if (!rut.match(/^[0-9]+([0-9]|k|K)$/)) {
    return cb('Input contains invalid characters', null)
  }

  if (rut.length !== 9 && rut.length !== 8) {
    return cb('Invalid RUT length', null)
  } else {
    getDigit(rut.slice(0,-1), function(err, digit){
      if (digit === rut[rut.length-1]) {
        return cb(null, true)
      } else {
        return cb(null, false)
      }

    })
  }
}

var getDigit = function (incompleteRut, cb){
  incompleteRut = incompleteRut.toString().trim()
  incompleteRut = incompleteRut.replace('.', '')
  incompleteRut = incompleteRut.replace('-', '')
  // check if incompleteRut only contains numbers
  if (!incompleteRut.match(/^[0-9]+$/)) {
    return cb('Input contains invalid characters', null)
  }
  if (incompleteRut.length !== 8 && incompleteRut.length !== 7) {
    return cb('Invalid RUT length', null)
  } else {
    var sum = 0
    var revRut = incompleteRut.split('').reverse().join('')
    for (var i = 0; i < incompleteRut.length; i++) {
      sum = sum + (parseInt(revRut[i]) * multipliers[i])
    }
    var value = 11 - (sum % 11)
    if (value > 0 && value <= 9) {
      value = value.toString()
      return cb(null, value)
    } else if (value === 10) {
      return cb(null, 'k')
    } else if (value === 11) {
      return cb(null, '0')
    }
  }
}

exports.getDigit = getDigit;
<commit_msg>refactor: change to use async await syntax<commit_after>const multipliers = [2, 3, 4, 5, 6, 7, 2, 3]

const verify = async (rut) => {
  // trim and remove dots and dashes
  rut = rut.toString()
    .trim()
  rut = rut.toLowerCase()
  rut = rut.replace('.', '')
  rut = rut.replace('-', '')

  // check if rut only contains numbers
  if (!rut.match(/^[0-9]+([0-9]|k|K)$/)) {
    throw new Error('Input contains invalid characters')
  }
  if (rut.length !== 9 && rut.length !== 8) {
    throw new Error('Invalid RUT length')
  } else {
    try {
      return await getDigit(rut.slice(0, -1)) === rut[rut.length - 1]
    } catch (e) {
      throw e
    }
  }
}

const getDigit = async (incompleteRut) => {
  incompleteRut = incompleteRut.toString()
    .trim()
  incompleteRut = incompleteRut.replace('.', '')
  incompleteRut = incompleteRut.replace('-', '')
  // check if incompleteRut only contains numbers
  if (!incompleteRut.match(/^[0-9]+$/)) {
    throw new Error('Input contains invalid characters')
  }
  if (incompleteRut.length !== 8 && incompleteRut.length !== 7) {
    throw new Error('Invalid RUT length')
  } else {
    var sum = 0
    var revRut = incompleteRut.split('')
      .reverse()
      .join('')
    for (var i = 0; i < incompleteRut.length; i++) {
      sum = sum + (parseInt(revRut[i]) * multipliers[i])
    }
    var value = 11 - (sum % 11)
    if (value > 0 && value <= 9) {
      value = value.toString()
      return value
    } else if (value === 10) {
      return 'k'
    } else if (value === 11) {
      return '0'
    }
  }
}



module.exports={
  verify, getDigit
}

{'fraction_non_alphanumeric': 0.17763361136855113, 'fraction_numerical': 0.02100710534445474, 'mean_word_length': 2.7048054919908466, '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': '3029558', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1118, 'n_words': 305}