@senior-agronegocio/angular-components 0.0.50 → 0.0.52

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.
@@ -2342,70 +2342,35 @@
2342
2342
  return matches ? matches.length : exports.AGRO_NUMBERS.ZERO;
2343
2343
  };
2344
2344
  AgroStringUtils.validateCPF = function (cpf) {
2345
- // Remover caracteres não numéricos
2346
2345
  cpf = cpf.replace(/\D/g, "");
2347
- // Verificar se o CPF tem 11 dígitos
2348
- if (cpf.length !== exports.AGRO_NUMBERS.ELEVEN) {
2346
+ if (cpf.length !== 11 || /^(\d)\1{10}$/.test(cpf)) {
2349
2347
  return false;
2350
2348
  }
2351
- // Verificar se todos os dígitos são iguais (caso contrário, é um sinal de CPF inválido)
2352
- if (/^(\d)\1{10}$/.test(cpf)) {
2353
- return false;
2354
- }
2355
- // Calcular o primeiro dígito verificador
2356
- var sum = exports.AGRO_NUMBERS.ZERO;
2357
- var remainder;
2358
- for (var i = exports.AGRO_NUMBERS.ONE; i <= exports.AGRO_NUMBERS.NINE; i++) {
2359
- sum += parseInt(cpf[i - exports.AGRO_NUMBERS.ONE]) * (exports.AGRO_NUMBERS.ELEVEN - i);
2360
- }
2361
- remainder = sum % exports.AGRO_NUMBERS.ELEVEN;
2362
- if (remainder === exports.AGRO_NUMBERS.TEN || remainder === exports.AGRO_NUMBERS.ELEVEN) {
2363
- remainder = exports.AGRO_NUMBERS.ZERO;
2364
- }
2365
- if (remainder !== parseInt(cpf[exports.AGRO_NUMBERS.NINE])) {
2366
- return false;
2367
- }
2368
- // Calcular o segundo dígito verificador
2369
- sum = exports.AGRO_NUMBERS.ZERO;
2370
- for (var i = exports.AGRO_NUMBERS.ONE; i <= exports.AGRO_NUMBERS.TEN; i++) {
2371
- sum += parseInt(cpf[i - exports.AGRO_NUMBERS.ONE]) * (exports.AGRO_NUMBERS.TWELVE - i);
2372
- }
2373
- remainder = sum % exports.AGRO_NUMBERS.ELEVEN;
2374
- if (remainder === exports.AGRO_NUMBERS.TEN || remainder === exports.AGRO_NUMBERS.ELEVEN) {
2375
- remainder = exports.AGRO_NUMBERS.ZERO;
2376
- }
2377
- if (remainder !== parseInt(cpf[exports.AGRO_NUMBERS.TEN])) {
2378
- return false;
2379
- }
2380
- return true;
2349
+ var calcCheckDigit = function (length) {
2350
+ var sum = 0;
2351
+ for (var i = 0; i < length; i++) {
2352
+ sum += Number(cpf[i]) * (length + 1 - i);
2353
+ }
2354
+ var remainder = sum % 11;
2355
+ return remainder < 2 ? 0 : 11 - remainder;
2356
+ };
2357
+ return (calcCheckDigit(9) === Number(cpf[9]) &&
2358
+ calcCheckDigit(10) === Number(cpf[10]));
2381
2359
  };
2382
2360
  AgroStringUtils.validateCNPJ = function (cnpj) {
2383
- // Remove todos os caracteres não numéricos
2384
2361
  cnpj = cnpj.replace(/\D/g, "");
2385
- // Verifica se tem 14 dígitos
2386
- if (cnpj.length !== 14)
2387
- return false;
2388
- // Verifica se o CNPJ é uma sequência repetida (ex: 11111111111111, 22222222222222, etc.)
2389
- if (/^(\d)\1{13}$/.test(cnpj))
2362
+ if (cnpj.length !== 14 || /^(\d)\1{13}$/.test(cnpj))
2390
2363
  return false;
2391
- // Cálculo do primeiro dígito verificador
2392
- var soma = 0;
2393
- var pesos1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
2394
- for (var i = 0; i < 12; i++) {
2395
- soma += parseInt(cnpj.charAt(i)) * pesos1[i];
2396
- }
2397
- var resto = soma % 11;
2398
- var digito1 = resto < 2 ? 0 : 11 - resto;
2399
- // Cálculo do segundo dígito verificador
2400
- soma = 0;
2401
- var pesos2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
2402
- for (var i = 0; i < 13; i++) {
2403
- soma += parseInt(cnpj.charAt(i)) * pesos2[i];
2404
- }
2405
- resto = soma % 11;
2406
- var digito2 = resto < 2 ? 0 : 11 - resto;
2407
- // Verifica se os dígitos verificadores são válidos
2408
- return parseInt(cnpj.charAt(12)) === digito1 && parseInt(cnpj.charAt(13)) === digito2;
2364
+ var calcularDigito = function (length) {
2365
+ var pesos = length === 12
2366
+ ? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
2367
+ : [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
2368
+ var soma = pesos.reduce(function (acc, peso, i) { return acc + Number(cnpj[i]) * peso; }, 0);
2369
+ var resto = soma % 11;
2370
+ return resto < 2 ? 0 : 11 - resto;
2371
+ };
2372
+ return (calcularDigito(12) === Number(cnpj[12]) &&
2373
+ calcularDigito(13) === Number(cnpj[13]));
2409
2374
  };
2410
2375
  /**
2411
2376
  * Método para aplicar uma máscara em uma string. Considere a máscara com valores 9 para aplicação
@@ -2506,7 +2471,7 @@
2506
2471
  /**
2507
2472
  * Retorna o usuário logado
2508
2473
  * Caso contrário, retorna uma instância de Error
2509
- * @returns string || instanceOf Error
2474
+ * @returns string || null
2510
2475
  */
2511
2476
  AgroPlatformUtils.getCurrentUserName = function () {
2512
2477
  var _a;
@@ -2517,7 +2482,6 @@
2517
2482
  return str;
2518
2483
  }
2519
2484
  }
2520
- console.error('Cookie: "com.senior.token" não encontrado.');
2521
2485
  return null;
2522
2486
  };
2523
2487
  /**
@@ -4696,7 +4660,7 @@
4696
4660
  this.ngUnsubscribe.next();
4697
4661
  this.ngUnsubscribe.complete();
4698
4662
  this.websocketService.disconnect();
4699
- this.socketConnection.next(false);
4663
+ this.socketConnection = false;
4700
4664
  };
4701
4665
  EventControlBoardComponent.prototype.callWebsocket = function () {
4702
4666
  var _this = this;