Separando funções para poder utilizar destructure na formatarCpfCnpj e não receber erro por causa do this
This commit is contained in:
parent
4f0a68d49a
commit
f3c96616b5
2 changed files with 69 additions and 63 deletions
|
@ -3,7 +3,6 @@
|
||||||
Biblioteca com funções para formatação de dados.
|
Biblioteca com funções para formatação de dados.
|
||||||
|
|
||||||
CPF/CNPJ: Retorna no CPF ou CNPJ de Acordo com o Tamanho da Entrada.
|
CPF/CNPJ: Retorna no CPF ou CNPJ de Acordo com o Tamanho da Entrada.
|
||||||
Conta Bancária: 1234-5
|
|
||||||
|
|
||||||
### Exemplos
|
### Exemplos
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
module.exports = {
|
|
||||||
// Entrada: 12345000 Saída: 12.345-000
|
// Entrada: 12345000 Saída: 12.345-000
|
||||||
formatarCep(txt) {
|
function formatarCep(txt) {
|
||||||
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
||||||
if (!soNumeros) return soNumeros;
|
if (!soNumeros) return soNumeros;
|
||||||
|
|
||||||
|
@ -13,9 +12,10 @@ module.exports = {
|
||||||
cep += '-' + soNumeros.slice(5, 8);
|
cep += '-' + soNumeros.slice(5, 8);
|
||||||
|
|
||||||
return cep;
|
return cep;
|
||||||
},
|
}
|
||||||
|
|
||||||
// Entrada: 12345678000100 Saida: 12.345.678/0001-00
|
// Entrada: 12345678000100 Saida: 12.345.678/0001-00
|
||||||
formatarCnpj(txt) {
|
function formatarCnpj(txt) {
|
||||||
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
||||||
if (!soNumeros) return soNumeros;
|
if (!soNumeros) return soNumeros;
|
||||||
|
|
||||||
|
@ -35,9 +35,10 @@ module.exports = {
|
||||||
cnpj += '-' + soNumeros.slice(12, 14)
|
cnpj += '-' + soNumeros.slice(12, 14)
|
||||||
|
|
||||||
return cnpj
|
return cnpj
|
||||||
},
|
}
|
||||||
|
|
||||||
// Entrada: 12345678900 Saída: 123.456.789-00
|
// Entrada: 12345678900 Saída: 123.456.789-00
|
||||||
formatarCpf(txt) {
|
function formatarCpf(txt) {
|
||||||
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
||||||
if (!soNumeros) return soNumeros;
|
if (!soNumeros) return soNumeros;
|
||||||
|
|
||||||
|
@ -54,17 +55,19 @@ module.exports = {
|
||||||
cpf += '-' + soNumeros.slice(9, 11)
|
cpf += '-' + soNumeros.slice(9, 11)
|
||||||
|
|
||||||
return cpf;
|
return cpf;
|
||||||
},
|
}
|
||||||
formatarCpfCnpj(txt) {
|
|
||||||
|
function formatarCpfCnpj(txt) {
|
||||||
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
||||||
if (soNumeros.length <= 11) {
|
if (soNumeros.length <= 11) {
|
||||||
return this.formatarCpf(txt);
|
return formatarCpf(txt);
|
||||||
} else {
|
} else {
|
||||||
return this.formatarCnpj(txt);
|
return formatarCnpj(txt);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Entrada: 12345 Saída: 1234-5
|
// Entrada: 12345 Saída: 1234-5
|
||||||
formatarContaBancaria(txt) {
|
function formatarContaBancaria(txt) {
|
||||||
const soNumeros = e.target.value.replace(/[^\d]/g, '')
|
const soNumeros = e.target.value.replace(/[^\d]/g, '')
|
||||||
if (!soNumeros) return soNumeros;
|
if (!soNumeros) return soNumeros;
|
||||||
|
|
||||||
|
@ -77,4 +80,8 @@ module.exports = {
|
||||||
|
|
||||||
return conta;
|
return conta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
formatarCep, formatarCnpj, formatarCpf, formatarCpfCnpj,
|
||||||
|
formatarContaBancaria
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue