jcinfo-utils 1.0.48 → 1.0.50

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 CHANGED
@@ -87,3 +87,7 @@ export function updateVersionDate(fs: Object): void
87
87
  export function updateVersionBuild(fs: Object, autoInc?: boolean): void
88
88
 
89
89
  export function encodeUriBase64(str: string): string
90
+
91
+ export function validarCPF(aValue: string): boolean
92
+
93
+ export function validarCNPJ(aValue: string): boolean
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jcinfo-utils",
3
- "version": "1.0.48",
3
+ "version": "1.0.50",
4
4
  "description": "Pacote de funções utilitárias",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -62,7 +62,7 @@ export function _updateDotEnv(fs, incrementBuild = false, filename = '.env') {
62
62
  saveArrayInFile(fs, content, filename)
63
63
  }
64
64
 
65
- const envProd = '.env.production.local'
65
+ const envProd = '.env'
66
66
  const envLocal = '.env.local'
67
67
  const envKey = 'VITE_VERSION'
68
68
 
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
- console.log('Cnpj: 05438177000199', validarCNPJ('05438177000198'))
124
- console.log('Cpf : 068816807-83', validarCPF('068816807-83'))
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))