@senior-agronegocio/angular-components 0.0.76 → 0.0.77

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.
@@ -2466,42 +2466,21 @@
2466
2466
  return matches ? matches.length : exports.AGRO_NUMBERS.ZERO;
2467
2467
  };
2468
2468
  AgroStringUtils.validateCPF = function (cpf) {
2469
- // Remover caracteres não numéricos
2470
- cpf = cpf.replace(/\D/g, "");
2471
- // Verificar se o CPF tem 11 dígitos
2472
- if (cpf.length !== exports.AGRO_NUMBERS.ELEVEN) {
2469
+ cpf = cpf.replace(/\D/g, '');
2470
+ if (cpf.length !== 11 || /^(\d)\1+$/.test(cpf)) {
2473
2471
  return false;
2474
2472
  }
2475
- // Verificar se todos os dígitos são iguais (caso contrário, é um sinal de CPF inválido)
2476
- if (/^(\d)\1{10}$/.test(cpf)) {
2477
- return false;
2478
- }
2479
- // Calcular o primeiro dígito verificador
2480
- var sum = exports.AGRO_NUMBERS.ZERO;
2481
- var remainder;
2482
- for (var i = exports.AGRO_NUMBERS.ONE; i <= exports.AGRO_NUMBERS.NINE; i++) {
2483
- sum += parseInt(cpf[i - exports.AGRO_NUMBERS.ONE]) * (exports.AGRO_NUMBERS.ELEVEN - i);
2484
- }
2485
- remainder = sum % exports.AGRO_NUMBERS.ELEVEN;
2486
- if (remainder === exports.AGRO_NUMBERS.TEN || remainder === exports.AGRO_NUMBERS.ELEVEN) {
2487
- remainder = exports.AGRO_NUMBERS.ZERO;
2488
- }
2489
- if (remainder !== parseInt(cpf[exports.AGRO_NUMBERS.NINE])) {
2490
- return false;
2491
- }
2492
- // Calcular o segundo dígito verificador
2493
- sum = exports.AGRO_NUMBERS.ZERO;
2494
- for (var i = exports.AGRO_NUMBERS.ONE; i <= exports.AGRO_NUMBERS.TEN; i++) {
2495
- sum += parseInt(cpf[i - exports.AGRO_NUMBERS.ONE]) * (exports.AGRO_NUMBERS.TWELVE - i);
2496
- }
2497
- remainder = sum % exports.AGRO_NUMBERS.ELEVEN;
2498
- if (remainder === exports.AGRO_NUMBERS.TEN || remainder === exports.AGRO_NUMBERS.ELEVEN) {
2499
- remainder = exports.AGRO_NUMBERS.ZERO;
2500
- }
2501
- if (remainder !== parseInt(cpf[exports.AGRO_NUMBERS.TEN])) {
2502
- return false;
2503
- }
2504
- return true;
2473
+ var calcVerifier = function (cpf, length) {
2474
+ var sum = 0;
2475
+ for (var i = 0; i < length; i++) {
2476
+ sum += parseInt(cpf[i]) * (length + 1 - i);
2477
+ }
2478
+ var result = sum % 11;
2479
+ return result < 2 ? 0 : 11 - result;
2480
+ };
2481
+ var digit1 = calcVerifier(cpf, 9);
2482
+ var digit2 = calcVerifier(cpf, 10);
2483
+ return digit1 === parseInt(cpf[9]) && digit2 === parseInt(cpf[10]);
2505
2484
  };
2506
2485
  AgroStringUtils.validateCNPJ = function (cnpj) {
2507
2486
  // Remove todos os caracteres não numéricos