@senior-agronegocio/angular-components 0.0.55 → 0.0.56

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.
@@ -2120,23 +2120,19 @@
2120
2120
  var remainder = sum % 11;
2121
2121
  return remainder < 2 ? 0 : 11 - remainder;
2122
2122
  };
2123
- return (calcCheckDigit(9) === Number(cpf[9]) &&
2124
- calcCheckDigit(10) === Number(cpf[10]));
2123
+ return calcCheckDigit(9) === Number(cpf[9]) && calcCheckDigit(10) === Number(cpf[10]);
2125
2124
  };
2126
2125
  AgroStringUtils.validateCNPJ = function (cnpj) {
2127
2126
  cnpj = cnpj.replace(/\D/g, "");
2128
2127
  if (cnpj.length !== 14 || /^(\d)\1{13}$/.test(cnpj))
2129
2128
  return false;
2130
2129
  var calcularDigito = function (length) {
2131
- var pesos = length === 12
2132
- ? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
2133
- : [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
2130
+ var pesos = length === 12 ? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] : [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
2134
2131
  var soma = pesos.reduce(function (acc, peso, i) { return acc + Number(cnpj[i]) * peso; }, 0);
2135
2132
  var resto = soma % 11;
2136
2133
  return resto < 2 ? 0 : 11 - resto;
2137
2134
  };
2138
- return (calcularDigito(12) === Number(cnpj[12]) &&
2139
- calcularDigito(13) === Number(cnpj[13]));
2135
+ return calcularDigito(12) === Number(cnpj[12]) && calcularDigito(13) === Number(cnpj[13]);
2140
2136
  };
2141
2137
  /**
2142
2138
  * Método para aplicar uma máscara em uma string. Considere a máscara com valores 9 para aplicação
@@ -2205,6 +2201,16 @@
2205
2201
  AgroStringUtils.isValidEmail = function (email) {
2206
2202
  return AGRO_REGEX.isEmail.test(email);
2207
2203
  };
2204
+ /**
2205
+ * Valida se uma string é uma placa de veículo BR válida ou não.
2206
+ * Retorna um booleano para indicar se é uma placa válida ou não.
2207
+ * @param plate - A string a ser verificada
2208
+ */
2209
+ AgroStringUtils.isValidLicensePlate = function (plate) {
2210
+ var oldFormat = /^[A-Z]{3}-?\d{4}$/;
2211
+ var mercosulFormat = /^[A-Z]{3}\d[A-Z]\d{2}$/;
2212
+ return oldFormat.test(plate) || mercosulFormat.test(plate);
2213
+ };
2208
2214
  return AgroStringUtils;
2209
2215
  }());
2210
2216
 
@@ -2866,6 +2872,17 @@
2866
2872
  }
2867
2873
  return AgroStringUtils.validateCNPJ(cnpj) ? null : { cnpjValidator: true };
2868
2874
  };
2875
+ /**
2876
+ * Verifica se a string informada é uma placa de veículo válido.
2877
+ * Se a validação for false, retorna um objeto com a chave licensePlate.
2878
+ */
2879
+ AgroFormValidator.licensePlateValidator = function (control) {
2880
+ var plate = control.value;
2881
+ if (!plate) {
2882
+ return null;
2883
+ }
2884
+ return AgroStringUtils.isValidLicensePlate(plate) ? null : { licensePlate: true };
2885
+ };
2869
2886
  return AgroFormValidator;
2870
2887
  }());
2871
2888