{"size": 640, "ext": "js", "max_stars_repo_path": "src/generate.js", "max_stars_repo_name": "xmacedo-zz/cpf", "max_stars_repo_stars_event_min_datetime": "2015-12-29T23:21:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-20T12:51:03.000Z", "max_issues_repo_path": "src/generate.js", "max_issues_repo_name": "aquarela-io/cpf", "max_issues_repo_issues_event_min_datetime": "2016-04-13T16:59:50.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-22T20:19:24.000Z", "max_forks_repo_path": "src/generate.js", "max_forks_repo_name": "aquarela-io/cpf", "max_forks_repo_forks_event_min_datetime": "2016-04-08T20:48:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T23:30:13.000Z"}
{"max_stars_count": 64, "max_issues_count": 11, "max_forks_count": 9, "avg_line_length": 25.6, "max_line_length": 63, "alphanum_fraction": 0.6359375}
const randomArray = require('random-array')
const getCd = require('./get-cd')
const format = require('./format')

/**
 * Generate a random CPF number.
 *
 * @param {boolean} [formatted=true] To get a formatted number.
 * @param {boolean} [invalid=false] To get invalid number.
 * @returns {string} CPF number.
 */
module.exports = (formatted = true, invalid = false) => {
  const digits = randomArray(0, 9).oned(9, { round: true })

  const dv = invalid
    ? randomArray(0, 9).oned(2, { round: true })
    : getCd(digits)

  const cpfNumber = [...digits, ...dv].join('')

    return formatted
      ? format(cpfNumber)
      : cpfNumber
}
