monkey-front-core 0.0.616 → 0.0.617

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.
@@ -312,7 +312,8 @@ class MonkeyEcxUtils {
312
312
  return `${formated}`;
313
313
  }
314
314
  if (country === 'us') {
315
- return doc;
315
+ formated = doc.replace(/^(\d{2})(\d{7})$/, '$1-$2');
316
+ return `${formated}`;
316
317
  }
317
318
  if (doc.length === 14) {
318
319
  const cleaned = doc.replace(/[^A-Za-z0-9]/g, '').toUpperCase();
@@ -569,6 +570,100 @@ class MonkeyEcxUtils {
569
570
  }
570
571
  return false;
571
572
  }
573
+ static isValidEIN(ein) {
574
+ const cleanedEIN = (ein === null || ein === void 0 ? void 0 : ein.replace(/\D/g, '')) || '';
575
+ if (cleanedEIN.length !== 9) {
576
+ return false;
577
+ }
578
+ const validPrefixes = [
579
+ '10',
580
+ '12',
581
+ '60',
582
+ '67',
583
+ '50',
584
+ '53',
585
+ '01',
586
+ '02',
587
+ '03',
588
+ '04',
589
+ '05',
590
+ '06',
591
+ '11',
592
+ '13',
593
+ '14',
594
+ '16',
595
+ '21',
596
+ '22',
597
+ '23',
598
+ '25',
599
+ '34',
600
+ '51',
601
+ '52',
602
+ '54',
603
+ '55',
604
+ '56',
605
+ '57',
606
+ '58',
607
+ '59',
608
+ '65',
609
+ '30',
610
+ '32',
611
+ '35',
612
+ '36',
613
+ '37',
614
+ '38',
615
+ '61',
616
+ '15',
617
+ '24',
618
+ '20',
619
+ '26',
620
+ '27',
621
+ '45',
622
+ '46',
623
+ '47',
624
+ '81',
625
+ '82',
626
+ '83',
627
+ '84',
628
+ '85',
629
+ '40',
630
+ '44',
631
+ '94',
632
+ '95',
633
+ '80',
634
+ '90',
635
+ '33',
636
+ '39',
637
+ '41',
638
+ '42',
639
+ '43',
640
+ '46',
641
+ '48',
642
+ '62',
643
+ '63',
644
+ '64',
645
+ '66',
646
+ '68',
647
+ '71',
648
+ '72',
649
+ '73',
650
+ '74',
651
+ '75',
652
+ '76',
653
+ '77',
654
+ '86',
655
+ '87',
656
+ '88',
657
+ '91',
658
+ '92',
659
+ '93',
660
+ '98',
661
+ '99',
662
+ '31'
663
+ ];
664
+ const prefix = cleanedEIN.substring(0, 2);
665
+ return validPrefixes.indexOf(prefix) !== -1;
666
+ }
572
667
  static isValidUrl(txt) {
573
668
  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;
574
669
  return regex.test(txt);
@@ -577,7 +672,8 @@ class MonkeyEcxUtils {
577
672
  const length = {
578
673
  br: 8,
579
674
  cl: 7,
580
- mx: 5
675
+ mx: 5,
676
+ us: 5
581
677
  }[country || 'br'];
582
678
  return `${this.handleOnlyNumbers(zipCode)}`.length === length;
583
679
  }
@@ -1281,6 +1377,20 @@ class DocumentRutValidator {
1281
1377
  return null;
1282
1378
  }
1283
1379
  }
1380
+ class DocumentEINValidator {
1381
+ static do(control) {
1382
+ if (!control.parent || !control)
1383
+ return null;
1384
+ if (control && control.value) {
1385
+ if (!MonkeyEcxUtils.isValidEIN(control.value)) {
1386
+ return {
1387
+ invalidEin: true
1388
+ };
1389
+ }
1390
+ }
1391
+ return null;
1392
+ }
1393
+ }
1284
1394
  class DocumentRFCValidator {
1285
1395
  static do(control) {
1286
1396
  if (!control.parent || !control)
@@ -1462,6 +1572,7 @@ var validateUtils = /*#__PURE__*/Object.freeze({
1462
1572
  DocumentValidator: DocumentValidator,
1463
1573
  AlphanumericDocumentValidator: AlphanumericDocumentValidator,
1464
1574
  DocumentRutValidator: DocumentRutValidator,
1575
+ DocumentEINValidator: DocumentEINValidator,
1465
1576
  DocumentRFCValidator: DocumentRFCValidator,
1466
1577
  ZipCodeValidator: ZipCodeValidator,
1467
1578
  ComboValidator: ComboValidator,
@@ -1622,6 +1733,13 @@ function documentValidator(control, country) {
1622
1733
  };
1623
1734
  }
1624
1735
  }
1736
+ else if (country === 'US') {
1737
+ if (!MonkeyEcxUtils.isValidEIN(control.value)) {
1738
+ return {
1739
+ invalidCpfCnpj: true
1740
+ };
1741
+ }
1742
+ }
1625
1743
  return null;
1626
1744
  }
1627
1745
  function minYearsValidator(param, control) {
@@ -1702,6 +1820,9 @@ function documentValidatorByType(type, control) {
1702
1820
  else if (type === 'RFC') {
1703
1821
  valid = MonkeyEcxUtils.isValidRFC(control.value);
1704
1822
  }
1823
+ else if (type === 'EIN') {
1824
+ valid = MonkeyEcxUtils.isValidEIN(control.value);
1825
+ }
1705
1826
  if (!valid) {
1706
1827
  return {
1707
1828
  [`invalid${MonkeyEcxUtils.capitalize(type.toLowerCase())}`]: true
@@ -1775,6 +1896,9 @@ class Validators {
1775
1896
  static documentMX(control) {
1776
1897
  return documentValidator(control, 'MX');
1777
1898
  }
1899
+ static documentUS(control) {
1900
+ return documentValidator(control, 'US');
1901
+ }
1778
1902
  static date(control) {
1779
1903
  return dateValidator(control);
1780
1904
  }