@bizy/core 19.14.4 → 19.14.5

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.
@@ -4141,23 +4141,27 @@ class BizyValidatorService {
4141
4141
  isUppercase = (value) => validator.isUppercase(value);
4142
4142
  isMobilePhone = (data) => validator.isMobilePhone(data.value, data.locale);
4143
4143
  isCUIT(cuit) {
4144
- const regex = /(^[0-9]{2}-[0-9]{8}-[0-9]$)/i;
4145
- const isCUIT = regex.test(String(cuit).toLowerCase());
4146
- if (!isCUIT) {
4144
+ if (!cuit) {
4147
4145
  return false;
4148
4146
  }
4149
- cuit = String(cuit).replace(/[-_]/g, '');
4150
- if (cuit.length == 11) {
4151
- const mult = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
4152
- let total = 0;
4153
- for (let i = 0; i < mult.length; i++) {
4154
- total += parseInt(cuit[i]) * mult[i];
4155
- }
4156
- const mod = total % 11;
4157
- const digit = mod === 0 ? 0 : mod === 1 ? 9 : 11 - mod;
4158
- return digit === parseInt(cuit[10]);
4147
+ if (this.isString(cuit)) {
4148
+ cuit = cuit.replace(/[-]/g, '');
4149
+ }
4150
+ else {
4151
+ cuit = String(cuit);
4152
+ }
4153
+ // 20, 23, 24, 25, 26 y 27 Personas Físicas
4154
+ // 30, 33 y 34 Personas Jurídicas.
4155
+ if (!/^(20|23|24|25|26|27|30|33|34)\d{8}\d$/.test(cuit)) {
4156
+ return false;
4159
4157
  }
4160
- return false;
4158
+ const multipliers = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
4159
+ const digits = cuit.split('').map(Number);
4160
+ const checkDigit = digits[10];
4161
+ const sum = multipliers.reduce((acc, _multiplier, i) => acc + _multiplier * digits[i], 0);
4162
+ const mod11 = 11 - (sum % 11);
4163
+ const expectedDigit = mod11 === 11 ? 0 : mod11 === 10 ? 9 : mod11;
4164
+ return checkDigit === expectedDigit;
4161
4165
  }
4162
4166
  isDNI(dni) {
4163
4167
  const regex = /(^[1-9]{1}[0-9]{7}$)/i;