@senior-agronegocio/angular-components 0.0.70-origination → 0.0.71-origination
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/bundles/senior-agronegocio-angular-components.umd.js +114 -5
- package/bundles/senior-agronegocio-angular-components.umd.js.map +1 -1
- package/bundles/senior-agronegocio-angular-components.umd.min.js +1 -1
- package/bundles/senior-agronegocio-angular-components.umd.min.js.map +1 -1
- package/common/agro-regex.constant.d.ts +10 -0
- package/esm2015/common/agro-regex.constant.js +11 -1
- package/esm2015/form-validator/agro-form-validator.js +94 -6
- package/esm5/common/agro-regex.constant.js +11 -1
- package/esm5/form-validator/agro-form-validator.js +106 -6
- package/fesm2015/senior-agronegocio-angular-components.js +103 -5
- package/fesm2015/senior-agronegocio-angular-components.js.map +1 -1
- package/fesm5/senior-agronegocio-angular-components.js +115 -6
- package/fesm5/senior-agronegocio-angular-components.js.map +1 -1
- package/form-validator/agro-form-validator.d.ts +14 -0
- package/package.json +1 -1
|
@@ -351,6 +351,16 @@
|
|
|
351
351
|
* Validação se todos os dígitos são iguais
|
|
352
352
|
*/
|
|
353
353
|
isAllDigitsEqual: /^(.)\1+$/,
|
|
354
|
+
/**
|
|
355
|
+
* Validação de Placa de Veículo do Mercosul
|
|
356
|
+
* Formato: ABC1D23
|
|
357
|
+
*/
|
|
358
|
+
isMercosulLicensePlate: /^[A-Z]{3}[0-9]{1}[A-Z]{1}[0-9]{2}$/,
|
|
359
|
+
/**
|
|
360
|
+
* Validação de Placa de Veículo Antiga
|
|
361
|
+
* Formato: AAA-0000
|
|
362
|
+
*/
|
|
363
|
+
isOldLicensePlate: /^[A-Z]{3}[0-9]{4}$/
|
|
354
364
|
};
|
|
355
365
|
|
|
356
366
|
|
|
@@ -1885,13 +1895,14 @@
|
|
|
1885
1895
|
AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
|
|
1886
1896
|
var checkValue = function (control) {
|
|
1887
1897
|
var _a, _b;
|
|
1888
|
-
var _c, _d, _e
|
|
1898
|
+
var _c, _d, _e;
|
|
1889
1899
|
var formGroup = control;
|
|
1890
1900
|
var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
|
|
1891
1901
|
var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1892
1902
|
var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
|
|
1893
1903
|
var methodName = 'checkValueBetween';
|
|
1894
|
-
|
|
1904
|
+
var areNumbers = [valueA, valueB, valueC].every(function (v) { return v !== null && v !== undefined; });
|
|
1905
|
+
if (areNumbers) {
|
|
1895
1906
|
if (valueB < valueA || valueB > valueC) {
|
|
1896
1907
|
var targetControl = formGroup.get(targetFormControl);
|
|
1897
1908
|
if (targetControl) {
|
|
@@ -1899,10 +1910,12 @@
|
|
|
1899
1910
|
}
|
|
1900
1911
|
return _b = {}, _b[methodName] = true, _b;
|
|
1901
1912
|
}
|
|
1902
|
-
else
|
|
1913
|
+
else {
|
|
1903
1914
|
var targetControl = formGroup.get(targetFormControl);
|
|
1904
|
-
if (targetControl) {
|
|
1905
|
-
targetControl.
|
|
1915
|
+
if (targetControl === null || targetControl === void 0 ? void 0 : targetControl.hasError(methodName)) {
|
|
1916
|
+
var errors = __assign({}, targetControl.errors);
|
|
1917
|
+
delete errors[methodName];
|
|
1918
|
+
targetControl.setErrors(Object.keys(errors).length ? errors : null);
|
|
1906
1919
|
}
|
|
1907
1920
|
}
|
|
1908
1921
|
}
|
|
@@ -1933,6 +1946,102 @@
|
|
|
1933
1946
|
};
|
|
1934
1947
|
return objectProperty;
|
|
1935
1948
|
};
|
|
1949
|
+
/**
|
|
1950
|
+
* Valida se o campo é um CPF (Cadastro de Pessoa Física) válido.
|
|
1951
|
+
*/
|
|
1952
|
+
AgroFormValidator.CPFValidator = function () {
|
|
1953
|
+
var cpfVal = function (control) {
|
|
1954
|
+
var cpf = (control.value || '').replace(/[^\d]/g, '');
|
|
1955
|
+
if (!cpf) {
|
|
1956
|
+
return null; // Não valida campo vazio, use Validators.required junto se quiser obrigatoriedade
|
|
1957
|
+
}
|
|
1958
|
+
if (cpf.length !== 11) {
|
|
1959
|
+
return { cpfValidator: true };
|
|
1960
|
+
}
|
|
1961
|
+
// Verifica se todos os dígitos são iguais (ex.: 11111111111)
|
|
1962
|
+
if (/^(\d)\1{10}$/.test(cpf)) {
|
|
1963
|
+
return { cpfValidator: true };
|
|
1964
|
+
}
|
|
1965
|
+
// Validação dos dígitos verificadores
|
|
1966
|
+
var calcCheckDigit = function (cpfSlice, factor) {
|
|
1967
|
+
var e_1, _a;
|
|
1968
|
+
var total = 0;
|
|
1969
|
+
try {
|
|
1970
|
+
for (var cpfSlice_1 = __values(cpfSlice), cpfSlice_1_1 = cpfSlice_1.next(); !cpfSlice_1_1.done; cpfSlice_1_1 = cpfSlice_1.next()) {
|
|
1971
|
+
var digit = cpfSlice_1_1.value;
|
|
1972
|
+
total += parseInt(digit, 10) * factor--;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1976
|
+
finally {
|
|
1977
|
+
try {
|
|
1978
|
+
if (cpfSlice_1_1 && !cpfSlice_1_1.done && (_a = cpfSlice_1.return)) _a.call(cpfSlice_1);
|
|
1979
|
+
}
|
|
1980
|
+
finally { if (e_1) throw e_1.error; }
|
|
1981
|
+
}
|
|
1982
|
+
var remainder = total % 11;
|
|
1983
|
+
return remainder < 2 ? 0 : 11 - remainder;
|
|
1984
|
+
};
|
|
1985
|
+
var digit1 = calcCheckDigit(cpf.substring(0, 9), 10);
|
|
1986
|
+
var digit2 = calcCheckDigit(cpf.substring(0, 9) + digit1, 11);
|
|
1987
|
+
var isValid = digit1 === parseInt(cpf.charAt(9), 10) &&
|
|
1988
|
+
digit2 === parseInt(cpf.charAt(10), 10);
|
|
1989
|
+
return isValid ? null : { cpfValidator: true };
|
|
1990
|
+
};
|
|
1991
|
+
return cpfVal;
|
|
1992
|
+
};
|
|
1993
|
+
/**
|
|
1994
|
+
* Validator de CNPJ (Cadastro Nacional da Pessoa Jurídica).
|
|
1995
|
+
* @returns
|
|
1996
|
+
*/
|
|
1997
|
+
AgroFormValidator.prototype.CNPJValidator = function () {
|
|
1998
|
+
return function (control) {
|
|
1999
|
+
var _a;
|
|
2000
|
+
var value = (_a = control.value) === null || _a === void 0 ? void 0 : _a.replace(/\D/g, '');
|
|
2001
|
+
if (!value || value.length !== 14) {
|
|
2002
|
+
return { cnpjValidator: true };
|
|
2003
|
+
}
|
|
2004
|
+
// Verifica CNPJs com todos os dígitos iguais (inválidos)
|
|
2005
|
+
if (/^(\d)\1{13}$/.test(value)) {
|
|
2006
|
+
return { cnpjValidator: true };
|
|
2007
|
+
}
|
|
2008
|
+
var validateCheckDigit = function (cnpj, length) {
|
|
2009
|
+
var weights = length === 12
|
|
2010
|
+
? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
2011
|
+
: [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
2012
|
+
var sum = cnpj
|
|
2013
|
+
.slice(0, length)
|
|
2014
|
+
.split('')
|
|
2015
|
+
.reduce(function (acc, digit, index) {
|
|
2016
|
+
return acc + parseInt(digit, 10) * weights[index];
|
|
2017
|
+
}, 0);
|
|
2018
|
+
var remainder = sum % 11;
|
|
2019
|
+
return remainder < 2 ? 0 : 11 - remainder;
|
|
2020
|
+
};
|
|
2021
|
+
var firstCheckDigit = validateCheckDigit(value, 12);
|
|
2022
|
+
var secondCheckDigit = validateCheckDigit(value, 13);
|
|
2023
|
+
if (firstCheckDigit !== parseInt(value.charAt(12), 10) ||
|
|
2024
|
+
secondCheckDigit !== parseInt(value.charAt(13), 10)) {
|
|
2025
|
+
return { cnpjValidator: true };
|
|
2026
|
+
}
|
|
2027
|
+
return null; // válido
|
|
2028
|
+
};
|
|
2029
|
+
};
|
|
2030
|
+
/**
|
|
2031
|
+
* Valida se a placa do veículo é válida.
|
|
2032
|
+
* @returns
|
|
2033
|
+
*/
|
|
2034
|
+
AgroFormValidator.prototype.licensePlateValidator = function () {
|
|
2035
|
+
return function (control) {
|
|
2036
|
+
var value = (control.value || '').toUpperCase().trim().replace(/-/g, '');
|
|
2037
|
+
if (!value) {
|
|
2038
|
+
return null; // Campo vazio não é responsabilidade desse validador
|
|
2039
|
+
}
|
|
2040
|
+
var isValid = AGRO_REGEX.isMercosulLicensePlate.test(value) ||
|
|
2041
|
+
AGRO_REGEX.isOldLicensePlate.test(value);
|
|
2042
|
+
return isValid ? null : { licensePlateInvalid: true };
|
|
2043
|
+
};
|
|
2044
|
+
};
|
|
1936
2045
|
return AgroFormValidator;
|
|
1937
2046
|
}());
|
|
1938
2047
|
|