Adicionada validação de CPF

This commit is contained in:
Luiz F Picolo 2024-05-29 20:12:33 -04:00
parent cba35fca03
commit ad8851d5d9
1 changed files with 14 additions and 5 deletions

View File

@ -3,16 +3,17 @@ import { cpf } from 'brazilian-doc-validator';
class PessoaFisica extends Pessoa {
#_cpf
#validarCPF
constructor(nome) {
super(nome)
}
set cpf(_cpf) {
if (cpf.validate(_cpf)){
this.#_cpf = _cpf
} else {
throw new Error("CPF Inválido")
try {
this.#_cpf = this.#validarCPF(_cpf)
} catch(erro){
console.log(erro.message)
}
}
@ -20,6 +21,14 @@ class PessoaFisica extends Pessoa {
return this.#_cpf
}
#validarCPF(_cpf){
if (!cpf.validate(_cpf)){
throw new Error("CPF Inválido")
}
return _cpf
}
mostrarDados(){
return `Meus dados são: ${this.nome} e ${this.cpf}`
}