ngx-vector-components 5.135.1 → 5.136.0
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/CHANGELOG.md +6 -0
- package/esm2022/lib/components/fields/dropdown-field/dropdown-field.component.mjs +3 -3
- package/esm2022/lib/utils/cpf-cnpj-validator.util.mjs +14 -31
- package/esm2022/lib/utils/mask.util.mjs +2 -2
- package/esm2022/lib/utils/validation.util.mjs +27 -16
- package/fesm2022/ngx-vector-components.mjs +43 -49
- package/fesm2022/ngx-vector-components.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -870,8 +870,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
|
|
|
870
870
|
|
|
871
871
|
class CpfCnpjValidator {
|
|
872
872
|
static validateCpfOrCnpj(taxId) {
|
|
873
|
-
taxId = taxId.replace(/[^
|
|
874
|
-
if (taxId.length == 11) {
|
|
873
|
+
taxId = taxId.replace(/[^a-zA-Z0-9]/g, '');
|
|
874
|
+
if (taxId.length == 11 && taxId.match(/^[0-9]+$/)) {
|
|
875
875
|
return this.validateCpf(taxId);
|
|
876
876
|
}
|
|
877
877
|
else if (taxId.length == 14) {
|
|
@@ -937,11 +937,18 @@ class CpfCnpjValidator {
|
|
|
937
937
|
return cpf === cpfAux;
|
|
938
938
|
}
|
|
939
939
|
static validateCnpj(cnpj) {
|
|
940
|
-
cnpj = cnpj.replace(/[
|
|
941
|
-
if (cnpj
|
|
940
|
+
cnpj = cnpj.replace(/[^a-zA-Z0-9]/g, '');
|
|
941
|
+
if (!cnpj || cnpj.length !== 14) {
|
|
942
942
|
return false;
|
|
943
|
-
|
|
943
|
+
}
|
|
944
|
+
const first12 = cnpj.substring(0, 12);
|
|
945
|
+
if (!first12.match(/^[a-zA-Z0-9]{12}$/)) {
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
const last2 = cnpj.substring(12, 14);
|
|
949
|
+
if (!last2.match(/^[0-9]{2}$/)) {
|
|
944
950
|
return false;
|
|
951
|
+
}
|
|
945
952
|
if ([
|
|
946
953
|
'00000000000000',
|
|
947
954
|
'11111111111111',
|
|
@@ -953,33 +960,9 @@ class CpfCnpjValidator {
|
|
|
953
960
|
'77777777777777',
|
|
954
961
|
'88888888888888',
|
|
955
962
|
'99999999999999',
|
|
956
|
-
].includes(cnpj))
|
|
957
|
-
return false;
|
|
958
|
-
let size = cnpj.length - 2;
|
|
959
|
-
let numbers = cnpj.substring(0, size);
|
|
960
|
-
let digits = cnpj.substring(size);
|
|
961
|
-
let sum = 0;
|
|
962
|
-
let pos = size - 7;
|
|
963
|
-
for (let i = size; i >= 1; i--) {
|
|
964
|
-
sum += parseInt(numbers.charAt(size - i)) * pos--;
|
|
965
|
-
if (pos < 2)
|
|
966
|
-
pos = 9;
|
|
967
|
-
}
|
|
968
|
-
let resultado = sum % 11 < 2 ? 0 : 11 - (sum % 11);
|
|
969
|
-
if (resultado != parseInt(digits.charAt(0)))
|
|
970
|
-
return false;
|
|
971
|
-
size = size + 1;
|
|
972
|
-
numbers = cnpj.substring(0, size);
|
|
973
|
-
sum = 0;
|
|
974
|
-
pos = size - 7;
|
|
975
|
-
for (let i = size; i >= 1; i--) {
|
|
976
|
-
sum += parseInt(numbers.charAt(size - i)) * pos--;
|
|
977
|
-
if (pos < 2)
|
|
978
|
-
pos = 9;
|
|
979
|
-
}
|
|
980
|
-
resultado = sum % 11 < 2 ? 0 : 11 - (sum % 11);
|
|
981
|
-
if (resultado != parseInt(digits.charAt(1)))
|
|
963
|
+
].includes(cnpj)) {
|
|
982
964
|
return false;
|
|
965
|
+
}
|
|
983
966
|
return true;
|
|
984
967
|
}
|
|
985
968
|
}
|
|
@@ -1010,7 +993,7 @@ const DNI_PATTERN = '##.###.###';
|
|
|
1010
993
|
const CUIT_PATTERN = '##-########-#';
|
|
1011
994
|
class MaskUtil {
|
|
1012
995
|
static { this.CPF_TEXT_FIELD_PATTERN = '999.999.999-99'; }
|
|
1013
|
-
static { this.CNPJ_TEXT_FIELD_PATTERN = '99
|
|
996
|
+
static { this.CNPJ_TEXT_FIELD_PATTERN = '**.***.***/****-99'; }
|
|
1014
997
|
static { this.BOLETO_TEXT_FIELD_PATTERN = '99999.99999 99999.999999 99999.999999 9 99999999999999 9'; }
|
|
1015
998
|
static { this.CELLPHONE_TEXT_FIELD_PATTERN = '(99) 99999-9999'; }
|
|
1016
999
|
static { this.PHONE_TEXT_FIELD_PATTERN = '(99) 9999-9999'; }
|
|
@@ -1250,26 +1233,37 @@ class ValidationUtil {
|
|
|
1250
1233
|
}
|
|
1251
1234
|
static isValidCnpj(control) {
|
|
1252
1235
|
let cnpj = control.value;
|
|
1253
|
-
cnpj = cnpj.replace(/[
|
|
1254
|
-
if (
|
|
1236
|
+
cnpj = cnpj.replace(/[^a-zA-Z0-9]/g, '');
|
|
1237
|
+
if (!cnpj || cnpj.length !== 14) {
|
|
1255
1238
|
return { cnpjNotValid: true };
|
|
1256
1239
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
s += n.charAt(x - i) * y--;
|
|
1261
|
-
if (y < 2)
|
|
1262
|
-
y = 9;
|
|
1263
|
-
}
|
|
1264
|
-
r = 11 - (s % 11);
|
|
1265
|
-
return r > 9 ? 0 : r;
|
|
1266
|
-
};
|
|
1267
|
-
if (calc(t) === d1 && calc(t + 1) === d2) {
|
|
1268
|
-
return null;
|
|
1240
|
+
const first12 = cnpj.substring(0, 12);
|
|
1241
|
+
if (!first12.match(/^[a-zA-Z0-9]{12}$/)) {
|
|
1242
|
+
return { cnpjNotValid: true };
|
|
1269
1243
|
}
|
|
1270
|
-
|
|
1244
|
+
const last2 = cnpj.substring(12, 14);
|
|
1245
|
+
if (!last2.match(/^[0-9]{2}$/)) {
|
|
1246
|
+
return { cnpjNotValid: true };
|
|
1247
|
+
}
|
|
1248
|
+
if (/^(\d)\1+$/.test(cnpj)) {
|
|
1271
1249
|
return { cnpjNotValid: true };
|
|
1272
1250
|
}
|
|
1251
|
+
if (/^[0-9]{14}$/.test(cnpj)) {
|
|
1252
|
+
let t = cnpj.length - 2, d = cnpj.substring(t), d1 = parseInt(d.charAt(0)), d2 = parseInt(d.charAt(1)), calc = (x) => {
|
|
1253
|
+
let n = cnpj.substring(0, x), y = x - 7, s = 0, r = 0;
|
|
1254
|
+
for (let i = x; i >= 1; i--) {
|
|
1255
|
+
s += n.charAt(x - i) * y--;
|
|
1256
|
+
if (y < 2)
|
|
1257
|
+
y = 9;
|
|
1258
|
+
}
|
|
1259
|
+
r = 11 - (s % 11);
|
|
1260
|
+
return r > 9 ? 0 : r;
|
|
1261
|
+
};
|
|
1262
|
+
if (calc(t) !== d1 || calc(t + 1) !== d2) {
|
|
1263
|
+
return { cnpjNotValid: true };
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return null;
|
|
1273
1267
|
}
|
|
1274
1268
|
static majorAge(control) {
|
|
1275
1269
|
if (!control.value) {
|
|
@@ -3469,8 +3463,8 @@ class DropdownFieldComponent {
|
|
|
3469
3463
|
if (firstDigitIndex === -1)
|
|
3470
3464
|
return value;
|
|
3471
3465
|
const prefix = value.slice(0, firstDigitIndex);
|
|
3472
|
-
const
|
|
3473
|
-
const match =
|
|
3466
|
+
const remainingValue = value.slice(firstDigitIndex);
|
|
3467
|
+
const match = remainingValue.match(/^([a-zA-Z0-9]+)(.*)$/);
|
|
3474
3468
|
if (!match)
|
|
3475
3469
|
return value;
|
|
3476
3470
|
const rawNumber = match[1];
|