@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __assign, __values, __read, __awaiter, __generator, __spread, __decorate, __extends } from 'tslib';
|
|
2
2
|
import moment from 'moment';
|
|
3
3
|
import { Subject, BehaviorSubject, of, throwError } from 'rxjs';
|
|
4
4
|
import sockjsClient from 'sockjs-client';
|
|
@@ -175,6 +175,16 @@ var AGRO_REGEX = {
|
|
|
175
175
|
* Validação se todos os dígitos são iguais
|
|
176
176
|
*/
|
|
177
177
|
isAllDigitsEqual: /^(.)\1+$/,
|
|
178
|
+
/**
|
|
179
|
+
* Validação de Placa de Veículo do Mercosul
|
|
180
|
+
* Formato: ABC1D23
|
|
181
|
+
*/
|
|
182
|
+
isMercosulLicensePlate: /^[A-Z]{3}[0-9]{1}[A-Z]{1}[0-9]{2}$/,
|
|
183
|
+
/**
|
|
184
|
+
* Validação de Placa de Veículo Antiga
|
|
185
|
+
* Formato: AAA-0000
|
|
186
|
+
*/
|
|
187
|
+
isOldLicensePlate: /^[A-Z]{3}[0-9]{4}$/
|
|
178
188
|
};
|
|
179
189
|
|
|
180
190
|
var NumberComparisonType;
|
|
@@ -1709,13 +1719,14 @@ var AgroFormValidator = /** @class */ (function () {
|
|
|
1709
1719
|
AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
|
|
1710
1720
|
var checkValue = function (control) {
|
|
1711
1721
|
var _a, _b;
|
|
1712
|
-
var _c, _d, _e
|
|
1722
|
+
var _c, _d, _e;
|
|
1713
1723
|
var formGroup = control;
|
|
1714
1724
|
var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
|
|
1715
1725
|
var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1716
1726
|
var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
|
|
1717
1727
|
var methodName = 'checkValueBetween';
|
|
1718
|
-
|
|
1728
|
+
var areNumbers = [valueA, valueB, valueC].every(function (v) { return v !== null && v !== undefined; });
|
|
1729
|
+
if (areNumbers) {
|
|
1719
1730
|
if (valueB < valueA || valueB > valueC) {
|
|
1720
1731
|
var targetControl = formGroup.get(targetFormControl);
|
|
1721
1732
|
if (targetControl) {
|
|
@@ -1723,10 +1734,12 @@ var AgroFormValidator = /** @class */ (function () {
|
|
|
1723
1734
|
}
|
|
1724
1735
|
return _b = {}, _b[methodName] = true, _b;
|
|
1725
1736
|
}
|
|
1726
|
-
else
|
|
1737
|
+
else {
|
|
1727
1738
|
var targetControl = formGroup.get(targetFormControl);
|
|
1728
|
-
if (targetControl) {
|
|
1729
|
-
targetControl.
|
|
1739
|
+
if (targetControl === null || targetControl === void 0 ? void 0 : targetControl.hasError(methodName)) {
|
|
1740
|
+
var errors = __assign({}, targetControl.errors);
|
|
1741
|
+
delete errors[methodName];
|
|
1742
|
+
targetControl.setErrors(Object.keys(errors).length ? errors : null);
|
|
1730
1743
|
}
|
|
1731
1744
|
}
|
|
1732
1745
|
}
|
|
@@ -1757,6 +1770,102 @@ var AgroFormValidator = /** @class */ (function () {
|
|
|
1757
1770
|
};
|
|
1758
1771
|
return objectProperty;
|
|
1759
1772
|
};
|
|
1773
|
+
/**
|
|
1774
|
+
* Valida se o campo é um CPF (Cadastro de Pessoa Física) válido.
|
|
1775
|
+
*/
|
|
1776
|
+
AgroFormValidator.CPFValidator = function () {
|
|
1777
|
+
var cpfVal = function (control) {
|
|
1778
|
+
var cpf = (control.value || '').replace(/[^\d]/g, '');
|
|
1779
|
+
if (!cpf) {
|
|
1780
|
+
return null; // Não valida campo vazio, use Validators.required junto se quiser obrigatoriedade
|
|
1781
|
+
}
|
|
1782
|
+
if (cpf.length !== 11) {
|
|
1783
|
+
return { cpfValidator: true };
|
|
1784
|
+
}
|
|
1785
|
+
// Verifica se todos os dígitos são iguais (ex.: 11111111111)
|
|
1786
|
+
if (/^(\d)\1{10}$/.test(cpf)) {
|
|
1787
|
+
return { cpfValidator: true };
|
|
1788
|
+
}
|
|
1789
|
+
// Validação dos dígitos verificadores
|
|
1790
|
+
var calcCheckDigit = function (cpfSlice, factor) {
|
|
1791
|
+
var e_1, _a;
|
|
1792
|
+
var total = 0;
|
|
1793
|
+
try {
|
|
1794
|
+
for (var cpfSlice_1 = __values(cpfSlice), cpfSlice_1_1 = cpfSlice_1.next(); !cpfSlice_1_1.done; cpfSlice_1_1 = cpfSlice_1.next()) {
|
|
1795
|
+
var digit = cpfSlice_1_1.value;
|
|
1796
|
+
total += parseInt(digit, 10) * factor--;
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1800
|
+
finally {
|
|
1801
|
+
try {
|
|
1802
|
+
if (cpfSlice_1_1 && !cpfSlice_1_1.done && (_a = cpfSlice_1.return)) _a.call(cpfSlice_1);
|
|
1803
|
+
}
|
|
1804
|
+
finally { if (e_1) throw e_1.error; }
|
|
1805
|
+
}
|
|
1806
|
+
var remainder = total % 11;
|
|
1807
|
+
return remainder < 2 ? 0 : 11 - remainder;
|
|
1808
|
+
};
|
|
1809
|
+
var digit1 = calcCheckDigit(cpf.substring(0, 9), 10);
|
|
1810
|
+
var digit2 = calcCheckDigit(cpf.substring(0, 9) + digit1, 11);
|
|
1811
|
+
var isValid = digit1 === parseInt(cpf.charAt(9), 10) &&
|
|
1812
|
+
digit2 === parseInt(cpf.charAt(10), 10);
|
|
1813
|
+
return isValid ? null : { cpfValidator: true };
|
|
1814
|
+
};
|
|
1815
|
+
return cpfVal;
|
|
1816
|
+
};
|
|
1817
|
+
/**
|
|
1818
|
+
* Validator de CNPJ (Cadastro Nacional da Pessoa Jurídica).
|
|
1819
|
+
* @returns
|
|
1820
|
+
*/
|
|
1821
|
+
AgroFormValidator.prototype.CNPJValidator = function () {
|
|
1822
|
+
return function (control) {
|
|
1823
|
+
var _a;
|
|
1824
|
+
var value = (_a = control.value) === null || _a === void 0 ? void 0 : _a.replace(/\D/g, '');
|
|
1825
|
+
if (!value || value.length !== 14) {
|
|
1826
|
+
return { cnpjValidator: true };
|
|
1827
|
+
}
|
|
1828
|
+
// Verifica CNPJs com todos os dígitos iguais (inválidos)
|
|
1829
|
+
if (/^(\d)\1{13}$/.test(value)) {
|
|
1830
|
+
return { cnpjValidator: true };
|
|
1831
|
+
}
|
|
1832
|
+
var validateCheckDigit = function (cnpj, length) {
|
|
1833
|
+
var weights = length === 12
|
|
1834
|
+
? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
1835
|
+
: [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
1836
|
+
var sum = cnpj
|
|
1837
|
+
.slice(0, length)
|
|
1838
|
+
.split('')
|
|
1839
|
+
.reduce(function (acc, digit, index) {
|
|
1840
|
+
return acc + parseInt(digit, 10) * weights[index];
|
|
1841
|
+
}, 0);
|
|
1842
|
+
var remainder = sum % 11;
|
|
1843
|
+
return remainder < 2 ? 0 : 11 - remainder;
|
|
1844
|
+
};
|
|
1845
|
+
var firstCheckDigit = validateCheckDigit(value, 12);
|
|
1846
|
+
var secondCheckDigit = validateCheckDigit(value, 13);
|
|
1847
|
+
if (firstCheckDigit !== parseInt(value.charAt(12), 10) ||
|
|
1848
|
+
secondCheckDigit !== parseInt(value.charAt(13), 10)) {
|
|
1849
|
+
return { cnpjValidator: true };
|
|
1850
|
+
}
|
|
1851
|
+
return null; // válido
|
|
1852
|
+
};
|
|
1853
|
+
};
|
|
1854
|
+
/**
|
|
1855
|
+
* Valida se a placa do veículo é válida.
|
|
1856
|
+
* @returns
|
|
1857
|
+
*/
|
|
1858
|
+
AgroFormValidator.prototype.licensePlateValidator = function () {
|
|
1859
|
+
return function (control) {
|
|
1860
|
+
var value = (control.value || '').toUpperCase().trim().replace(/-/g, '');
|
|
1861
|
+
if (!value) {
|
|
1862
|
+
return null; // Campo vazio não é responsabilidade desse validador
|
|
1863
|
+
}
|
|
1864
|
+
var isValid = AGRO_REGEX.isMercosulLicensePlate.test(value) ||
|
|
1865
|
+
AGRO_REGEX.isOldLicensePlate.test(value);
|
|
1866
|
+
return isValid ? null : { licensePlateInvalid: true };
|
|
1867
|
+
};
|
|
1868
|
+
};
|
|
1760
1869
|
return AgroFormValidator;
|
|
1761
1870
|
}());
|
|
1762
1871
|
|