<commit_before>"use strict";

const calcDv = require("./calc-dv");
const formatar = require("./format");

function generate(formatted = true, invalid = false) {
  const formatado = formatted;
  const invalido = invalid;

  const gerarNum = max => () => Math.floor(Math.random() * (max + 1));
  const criarArrAleatoria = (tamanho, max) => Array.from(Array(tamanho), gerarNum(max));

  const digitos = criarArrAleatoria(9, 9);

  if (invalido) {
    const pseudoDv = criarArrAleatoria(2, 9);
    const pseudoCpf = digitos.concat(pseudoDv);
    const pseudoCpfEmStr = pseudoCpf.join("");

    return formatado
      ? formatar(pseudoCpfEmStr)
      : pseudoCpfEmStr;
  }

  const dv = calcDv(digitos);
  const dvEmStr = dv.toString();
  const digitosEmStr = digitos.join("");
  const cpf = digitosEmStr + dvEmStr;

  return formatado
    ? formatar(cpf)
    : cpf;
}

module.exports = generate;
<commit_msg>corrige geração de cpf desformatado<commit_after>"use strict";

const calcDv = require("./calc-dv");
const formatar = require("./format");

function generate(formatted = true, invalid = false) {
  const formatado = formatted;
  const invalido = invalid;

  const gerarNum = max => () => Math.floor(Math.random() * (max + 1));
  const criarArrAleatoria = (tamanho, max) => Array.from(Array(tamanho), gerarNum(max));

  const digitos = criarArrAleatoria(9, 9);

  if (invalido) {
    const pseudoDv = criarArrAleatoria(2, 9);
    const pseudoCpf = digitos.concat(pseudoDv);
    const pseudoCpfEmStr = pseudoCpf.join("");

    return formatado
      ? formatar(pseudoCpfEmStr)
      : pseudoCpfEmStr;
  }

  const dv = calcDv(digitos);
  const dvEmStr = dv.join("");
  const digitosEmStr = digitos.join("");
  const cpf = digitosEmStr + dvEmStr;

  return formatado
    ? formatar(cpf)
    : cpf;
}

module.exports = generate;

{'fraction_non_alphanumeric': 0.13785557986870897, 'fraction_numerical': 0.005470459518599562, 'mean_word_length': 3.903485254691689, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6109532', 'n_tokens_mistral': 662, 'n_tokens_neox': 641, 'n_words': 144}