jcinfo-utils 1.0.47 → 1.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +2 -0
- package/index.js +2 -1
- package/package.json +1 -1
- package/src/utils.js +5 -0
- package/src/validator.js +12 -15
- package/test/testar.js +5 -2
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from './src/updateDotEnv.js'
|
|
18
18
|
import { formatFileSize } from './src/formatFileSize.js'
|
|
19
19
|
import { retirarAcentuacao } from './src/retirarAcentuacao.js'
|
|
20
|
-
import { fileExists } from './src/utils.js'
|
|
20
|
+
import { fileExists, encodeUriBase64 } from './src/utils.js'
|
|
21
21
|
import { validarCPF, validarCNPJ } from './src/validator.js'
|
|
22
22
|
|
|
23
23
|
// ===================================================== CONFIGURAÇÕES
|
|
@@ -230,6 +230,7 @@ export {
|
|
|
230
230
|
formatFileSize,
|
|
231
231
|
retirarAcentuacao,
|
|
232
232
|
fileExists,
|
|
233
|
+
encodeUriBase64,
|
|
233
234
|
updateDotEnv,
|
|
234
235
|
updateDotEnvKey,
|
|
235
236
|
updateVersionDate,
|
package/package.json
CHANGED
package/src/utils.js
CHANGED
package/src/validator.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Função para validar CNPJ
|
|
3
|
+
* @param {string} aValue Número do CNPJ com ou sem máscara
|
|
4
|
+
* @returns {boolean}
|
|
5
|
+
*/
|
|
1
6
|
export function validarCNPJ(aValue) {
|
|
2
7
|
let acumulador = 0
|
|
3
8
|
let contador = 5
|
|
4
9
|
let finalChar = 12
|
|
5
10
|
let strDigito = ''
|
|
6
|
-
|
|
7
11
|
// Função para remover caracteres não numéricos
|
|
8
12
|
function soNumeros(value) {
|
|
9
13
|
return value.replace(/\D/g, '')
|
|
10
14
|
}
|
|
11
|
-
|
|
12
15
|
aValue = soNumeros(aValue)
|
|
13
|
-
|
|
14
16
|
if (aValue === '') {
|
|
15
17
|
return false
|
|
16
18
|
}
|
|
17
|
-
|
|
18
19
|
if (aValue.length !== 14) {
|
|
19
20
|
return false
|
|
20
21
|
}
|
|
21
|
-
|
|
22
22
|
for (let i = 0; i < 2; i++) {
|
|
23
23
|
for (let j = 0; j < finalChar; j++) {
|
|
24
24
|
acumulador += parseInt(aValue[j]) * contador
|
|
@@ -32,38 +32,36 @@ export function validarCNPJ(aValue) {
|
|
|
32
32
|
contador = 6
|
|
33
33
|
finalChar = 13
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
return aValue.substr(12, 2) === strDigito
|
|
35
|
+
return aValue.substring(12, 14) === strDigito
|
|
37
36
|
}
|
|
38
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Função para validar CPF
|
|
40
|
+
* @param {string} aValue Número de CPF a validar com ou sem máscara
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
39
43
|
export function validarCPF(aValue) {
|
|
40
44
|
let acumulador = 0
|
|
41
45
|
let contador = 10
|
|
42
46
|
let finalChar = 9
|
|
43
47
|
let numerosCpf = ''
|
|
44
48
|
let strDigito = ''
|
|
45
|
-
|
|
46
49
|
// Função para remover caracteres não numéricos
|
|
47
50
|
function soNumeros(value) {
|
|
48
51
|
return value.replace(/\D/g, '')
|
|
49
52
|
}
|
|
50
|
-
|
|
51
53
|
numerosCpf = soNumeros(aValue)
|
|
52
|
-
|
|
53
54
|
if (numerosCpf.trim() === '') {
|
|
54
55
|
return false
|
|
55
56
|
}
|
|
56
|
-
|
|
57
57
|
if (numerosCpf.length !== 11) {
|
|
58
58
|
return false
|
|
59
59
|
}
|
|
60
|
-
|
|
61
60
|
for (let i = 0; i < 2; i++) {
|
|
62
61
|
for (let j = 0; j < finalChar; j++) {
|
|
63
62
|
acumulador += parseInt(numerosCpf[j]) * contador
|
|
64
63
|
contador--
|
|
65
64
|
}
|
|
66
|
-
|
|
67
65
|
let digito = Math.abs(11 - (acumulador % 11))
|
|
68
66
|
digito = digito > 9 ? 0 : digito
|
|
69
67
|
strDigito += digito.toString()
|
|
@@ -71,6 +69,5 @@ export function validarCPF(aValue) {
|
|
|
71
69
|
contador = 11
|
|
72
70
|
finalChar = 10
|
|
73
71
|
}
|
|
74
|
-
|
|
75
|
-
return numerosCpf.substr(9, 2) === strDigito
|
|
72
|
+
return numerosCpf.substring(9, 11) === strDigito
|
|
76
73
|
}
|
package/test/testar.js
CHANGED
|
@@ -120,5 +120,8 @@ import { validarCNPJ, validarCPF } from '../src/validator.js'
|
|
|
120
120
|
console.groupEnd()
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
const cpf = '068.816.807-83',
|
|
124
|
+
cnpj = '05.438.177/0001-98'
|
|
125
|
+
|
|
126
|
+
console.log(`Cpf : ${cpf}`, validarCPF(cpf))
|
|
127
|
+
console.log(`Cnpj: ${cnpj}`, validarCNPJ(cnpj))
|