monkey-front-core 0.0.510 → 0.0.512
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/esm2020/lib/core/utils/statics.mjs +3 -1
- package/esm2020/lib/core/utils/utils.mjs +36 -2
- package/esm2020/lib/core/utils/validate-utils.mjs +15 -1
- package/esm2020/lib/core/utils/validators.mjs +15 -1
- package/fesm2015/monkey-front-core.mjs +66 -1
- package/fesm2015/monkey-front-core.mjs.map +1 -1
- package/fesm2020/monkey-front-core.mjs +66 -1
- package/fesm2020/monkey-front-core.mjs.map +1 -1
- package/lib/core/utils/statics.d.ts +3 -1
- package/lib/core/utils/utils.d.ts +2 -1
- package/lib/core/utils/validate-utils.d.ts +5 -0
- package/lib/core/utils/validators.d.ts +1 -0
- package/monkey-front-core-0.0.512.tgz +0 -0
- package/package.json +3 -3
- package/monkey-front-core-0.0.510.tgz +0 -0
|
@@ -129,6 +129,8 @@ var CountryMasks;
|
|
|
129
129
|
CountryMasks["CNPJ"] = "00.000.000/0000-00";
|
|
130
130
|
CountryMasks["RUT1"] = "0000000-A";
|
|
131
131
|
CountryMasks["RUT2"] = "00000000-A";
|
|
132
|
+
CountryMasks["RFC1"] = "AAA000000AA0";
|
|
133
|
+
CountryMasks["RFC2"] = "AAAA000000AA0";
|
|
132
134
|
})(CountryMasks || (CountryMasks = {}));
|
|
133
135
|
|
|
134
136
|
var statics = /*#__PURE__*/Object.freeze({
|
|
@@ -152,6 +154,8 @@ class MonkeyEcxUtils {
|
|
|
152
154
|
return '';
|
|
153
155
|
if (country === 'cl')
|
|
154
156
|
return 'RUT';
|
|
157
|
+
if (country === 'mx')
|
|
158
|
+
return 'RFC';
|
|
155
159
|
return doc.length <= 11 ? 'CPF' : 'CNPJ';
|
|
156
160
|
}
|
|
157
161
|
static getDocumentMask(type, country = '') {
|
|
@@ -165,6 +169,11 @@ class MonkeyEcxUtils {
|
|
|
165
169
|
CPF: CountryMasks.RUT1,
|
|
166
170
|
CNPJ: CountryMasks.RUT2,
|
|
167
171
|
'': `${CountryMasks.RUT1}||${CountryMasks.RUT2}`
|
|
172
|
+
},
|
|
173
|
+
MX: {
|
|
174
|
+
CPF: CountryMasks.RFC1,
|
|
175
|
+
CNPJ: CountryMasks.RFC2,
|
|
176
|
+
'': `${CountryMasks.RFC1}||${CountryMasks.RFC2}`
|
|
168
177
|
}
|
|
169
178
|
}[country.toUpperCase()]?.[type];
|
|
170
179
|
}
|
|
@@ -177,6 +186,10 @@ class MonkeyEcxUtils {
|
|
|
177
186
|
CL: {
|
|
178
187
|
CPF: '0000000-A',
|
|
179
188
|
CNPJ: '0000000-A'
|
|
189
|
+
},
|
|
190
|
+
MX: {
|
|
191
|
+
CPF: CountryMasks.RFC1,
|
|
192
|
+
CNPJ: CountryMasks.RFC2
|
|
180
193
|
}
|
|
181
194
|
}[country.toUpperCase()]?.[type];
|
|
182
195
|
}
|
|
@@ -277,12 +290,35 @@ class MonkeyEcxUtils {
|
|
|
277
290
|
const dvCalc = calcDv(num);
|
|
278
291
|
return dvCalc === dgv;
|
|
279
292
|
}
|
|
293
|
+
static isValidRFC(document) {
|
|
294
|
+
const regex = /^[A-Z]{4}[0-9]{6}[A-Z0-9]{3}$/;
|
|
295
|
+
if (!regex.test(document)) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
const year = parseInt(document.substr(4, 2));
|
|
299
|
+
const month = parseInt(document.substr(6, 2));
|
|
300
|
+
const day = parseInt(document.substr(8, 2));
|
|
301
|
+
if (year < 0 || year > 99) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
if (month < 1 || month > 12) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
if (day < 1 || day > 31) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
280
312
|
static isValidUrl(txt) {
|
|
281
313
|
const regex = /(https?:\/\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])(:?\d*)\/?([a-z_\\/0-9\-#.]*)\??([a-z_\\/0-9\-#=&]*)/g;
|
|
282
314
|
return regex.test(txt);
|
|
283
315
|
}
|
|
284
316
|
static isValidZipCode(zipCode, country) {
|
|
285
|
-
const length =
|
|
317
|
+
const length = {
|
|
318
|
+
'br': 8,
|
|
319
|
+
'cl': 7,
|
|
320
|
+
'mx': 5
|
|
321
|
+
}[country || 'br'];
|
|
286
322
|
return `${this.handleOnlyNumbers(zipCode)}`.length === length;
|
|
287
323
|
}
|
|
288
324
|
static isValidEmail(email) {
|
|
@@ -891,6 +927,20 @@ class DocumentRutValidator {
|
|
|
891
927
|
return null;
|
|
892
928
|
}
|
|
893
929
|
}
|
|
930
|
+
class DocumentRFCValidator {
|
|
931
|
+
static do(control) {
|
|
932
|
+
if (!control.parent || !control)
|
|
933
|
+
return null;
|
|
934
|
+
if (control && control.value) {
|
|
935
|
+
if (!MonkeyEcxUtils.isValidRFC(control.value)) {
|
|
936
|
+
return {
|
|
937
|
+
invalidRut: true
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
return null;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
894
944
|
class ZipCodeValidator {
|
|
895
945
|
static do(control) {
|
|
896
946
|
if (!control.parent || !control)
|
|
@@ -1053,6 +1103,7 @@ var validateUtils = /*#__PURE__*/Object.freeze({
|
|
|
1053
1103
|
DateValidator: DateValidator,
|
|
1054
1104
|
DocumentValidator: DocumentValidator,
|
|
1055
1105
|
DocumentRutValidator: DocumentRutValidator,
|
|
1106
|
+
DocumentRFCValidator: DocumentRFCValidator,
|
|
1056
1107
|
ZipCodeValidator: ZipCodeValidator,
|
|
1057
1108
|
ComboValidator: ComboValidator,
|
|
1058
1109
|
isTrueValidator: isTrueValidator,
|
|
@@ -1233,6 +1284,7 @@ function zipCodeValidator(control, country) {
|
|
|
1233
1284
|
function documentValidator(control, country) {
|
|
1234
1285
|
if (!control.parent || !control || isEmptyInputValue(control.value))
|
|
1235
1286
|
return null;
|
|
1287
|
+
country = `${country}`.toUpperCase();
|
|
1236
1288
|
if (country === 'BR') {
|
|
1237
1289
|
if (!MonkeyEcxUtils.isCPFCNPJValid(control.value)) {
|
|
1238
1290
|
return {
|
|
@@ -1247,6 +1299,13 @@ function documentValidator(control, country) {
|
|
|
1247
1299
|
};
|
|
1248
1300
|
}
|
|
1249
1301
|
}
|
|
1302
|
+
else if (country === 'MX') {
|
|
1303
|
+
if (!MonkeyEcxUtils.isValidRFC(control.value)) {
|
|
1304
|
+
return {
|
|
1305
|
+
invalidCpfCnpj: true
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1250
1309
|
return null;
|
|
1251
1310
|
}
|
|
1252
1311
|
function dateValidator(control) {
|
|
@@ -1310,6 +1369,9 @@ function documentValidatorByType(type, control) {
|
|
|
1310
1369
|
else if (type === 'RUT') {
|
|
1311
1370
|
valid = MonkeyEcxUtils.isValidRUT(control.value);
|
|
1312
1371
|
}
|
|
1372
|
+
else if (type === 'RFC') {
|
|
1373
|
+
valid = MonkeyEcxUtils.isValidRFC(control.value);
|
|
1374
|
+
}
|
|
1313
1375
|
if (!valid) {
|
|
1314
1376
|
return {
|
|
1315
1377
|
[`invalid${MonkeyEcxUtils.capitalize(type.toLowerCase())}`]: true
|
|
@@ -1359,6 +1421,9 @@ class Validators {
|
|
|
1359
1421
|
static documentCL(control) {
|
|
1360
1422
|
return documentValidator(control, 'CL');
|
|
1361
1423
|
}
|
|
1424
|
+
static documentMX(control) {
|
|
1425
|
+
return documentValidator(control, 'MX');
|
|
1426
|
+
}
|
|
1362
1427
|
static date(control) {
|
|
1363
1428
|
return dateValidator(control);
|
|
1364
1429
|
}
|