coer-elements 2.0.78 → 2.0.80
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.
@@ -685,6 +685,99 @@ class ControlValue {
|
|
685
685
|
}
|
686
686
|
}
|
687
687
|
|
688
|
+
/** Provides several methods for string manipulation */
|
689
|
+
class Strings {
|
690
|
+
/** Sets the first character to lowercase */
|
691
|
+
static FirstCharToLower(value) {
|
692
|
+
return (Tools.IsNotOnlyWhiteSpace(value))
|
693
|
+
? String(value).charAt(0).toLowerCase() + String(value).slice(1)
|
694
|
+
: '';
|
695
|
+
}
|
696
|
+
/** Sets the first character to uppercase */
|
697
|
+
static FirstCharToUpper(value) {
|
698
|
+
return (Tools.IsNotOnlyWhiteSpace(value))
|
699
|
+
? String(value).charAt(0).toUpperCase() + String(value).slice(1)
|
700
|
+
: '';
|
701
|
+
}
|
702
|
+
/** Clean extra whitespaces */
|
703
|
+
static CleanUpBlanks(value) {
|
704
|
+
return value && Tools.IsNotOnlyWhiteSpace(value)
|
705
|
+
? String(value).replace(/\s+/g, ' ').trim()
|
706
|
+
: '';
|
707
|
+
}
|
708
|
+
/** Apply title formatting */
|
709
|
+
static ToTitle(value) {
|
710
|
+
return (Tools.IsNotOnlyWhiteSpace(value))
|
711
|
+
? String(value).split(' ').filter(x => x.length > 0).map(x => Strings.FirstCharToUpper(x.toLowerCase())).join(' ')
|
712
|
+
: '';
|
713
|
+
}
|
714
|
+
/** Removes the last character */
|
715
|
+
static RemoveLastChar(value) {
|
716
|
+
return Tools.IsNotOnlyWhiteSpace(value)
|
717
|
+
? String(value).trimEnd().slice(0, -1)
|
718
|
+
: '';
|
719
|
+
}
|
720
|
+
/** Removes accents */
|
721
|
+
static RemoveAccents(value, except = []) {
|
722
|
+
if (Tools.IsOnlyWhiteSpace(value))
|
723
|
+
return '';
|
724
|
+
if (except.length > 0) {
|
725
|
+
let index = 0;
|
726
|
+
const mapValue = new Map();
|
727
|
+
for (const char of String(value)) {
|
728
|
+
mapValue.set(index++, char);
|
729
|
+
}
|
730
|
+
index = 0;
|
731
|
+
const mapNormalize = new Map();
|
732
|
+
for (const char of String(value).normalize('NFD').replace(/[\u0300-\u036f]/g, '')) {
|
733
|
+
mapNormalize.set(index++, char);
|
734
|
+
}
|
735
|
+
for (const char of except) {
|
736
|
+
for (const [index, value] of mapValue.entries()) {
|
737
|
+
if (value === char) {
|
738
|
+
mapNormalize.set(index, char);
|
739
|
+
}
|
740
|
+
}
|
741
|
+
}
|
742
|
+
return Array.from(mapNormalize.values()).join('');
|
743
|
+
}
|
744
|
+
else {
|
745
|
+
return String(value).normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
746
|
+
}
|
747
|
+
}
|
748
|
+
/** Removes special characters */
|
749
|
+
static RemoveSpecialCharacters(value) {
|
750
|
+
return (Tools.IsNotOnlyWhiteSpace(value))
|
751
|
+
? String(value).replace(/[^a-zA-Z0-9áéíóúÁÉÍÓÚüÜñÑ\s]/g, '') : '';
|
752
|
+
}
|
753
|
+
/** Only Alphanumeric */
|
754
|
+
static OnlyAlphanumeric(value) {
|
755
|
+
return (Tools.IsNotOnlyWhiteSpace(value))
|
756
|
+
? String(value).replace(/[^a-zA-Z0-9\s]/g, '') : '';
|
757
|
+
}
|
758
|
+
/** Only Alphanumeric */
|
759
|
+
static OnlyNumbers(value) {
|
760
|
+
return (Tools.IsNotOnlyWhiteSpace(value))
|
761
|
+
? String(value).replace(/[^0-9\s]/g, '') : '';
|
762
|
+
}
|
763
|
+
/** Validates if both strings are equal */
|
764
|
+
static Equals(value, value2, sensitive = false) {
|
765
|
+
if (typeof value === null && typeof value2 === null)
|
766
|
+
return true;
|
767
|
+
if (typeof value === 'undefined' && typeof value2 === 'undefined')
|
768
|
+
return true;
|
769
|
+
if (typeof value === 'string' && typeof value2 === 'string') {
|
770
|
+
if (!sensitive) {
|
771
|
+
value = value.toUpperCase();
|
772
|
+
value2 = value2.toUpperCase();
|
773
|
+
}
|
774
|
+
return value.length === value2.length
|
775
|
+
&& value === value2;
|
776
|
+
}
|
777
|
+
return false;
|
778
|
+
}
|
779
|
+
}
|
780
|
+
|
688
781
|
/** Provides several methods for dates manipulation */
|
689
782
|
class Dates {
|
690
783
|
static { this.MONTHS = new Map([
|
@@ -705,9 +798,13 @@ class Dates {
|
|
705
798
|
}
|
706
799
|
/** */
|
707
800
|
static _CleanDate(date) {
|
708
|
-
|
709
|
-
|
710
|
-
:
|
801
|
+
if (typeof date === 'string') {
|
802
|
+
date = Strings.CleanUpBlanks(date.replace(/(?:at|AT|t|T)/g, ' '));
|
803
|
+
return /\b([01]?\d|2[0-3]):[0-5]\d(:[0-5]\d)?\b/.test(date)
|
804
|
+
? new Date(date) : new Date(`${date} 00:00:00`);
|
805
|
+
}
|
806
|
+
else
|
807
|
+
return date;
|
711
808
|
}
|
712
809
|
/** Convert UTC Date to Local Zone. YYYY-MM-DD HH:mm:ss */
|
713
810
|
static ToLocalZone(utcDate) {
|
@@ -749,11 +846,11 @@ class Dates {
|
|
749
846
|
+ `${DATE.getDate()}`.padStart(2, '0') + ' ';
|
750
847
|
}
|
751
848
|
/** */
|
752
|
-
static GetFormatDate(date) {
|
753
|
-
switch (Tools.AvoidNull(appSettings?.dateTime?.format, 'string')) {
|
754
|
-
case 'MDY': return this._GetFormatDateMDY(date);
|
849
|
+
static GetFormatDate(date, format) {
|
850
|
+
switch (format || Tools.AvoidNull(appSettings?.dateTime?.format, 'string')) {
|
755
851
|
case 'DMY': return this._GetFormatDateDMY(date);
|
756
|
-
|
852
|
+
case 'YMD': return this._GetFormatDateYMD(date);
|
853
|
+
default: return this._GetFormatDateMDY(date);
|
757
854
|
}
|
758
855
|
}
|
759
856
|
/** */
|
@@ -1013,99 +1110,6 @@ class HTMLElements {
|
|
1013
1110
|
}
|
1014
1111
|
;
|
1015
1112
|
|
1016
|
-
/** Provides several methods for string manipulation */
|
1017
|
-
class Strings {
|
1018
|
-
/** Sets the first character to lowercase */
|
1019
|
-
static FirstCharToLower(value) {
|
1020
|
-
return (Tools.IsNotOnlyWhiteSpace(value))
|
1021
|
-
? String(value).charAt(0).toLowerCase() + String(value).slice(1)
|
1022
|
-
: '';
|
1023
|
-
}
|
1024
|
-
/** Sets the first character to uppercase */
|
1025
|
-
static FirstCharToUpper(value) {
|
1026
|
-
return (Tools.IsNotOnlyWhiteSpace(value))
|
1027
|
-
? String(value).charAt(0).toUpperCase() + String(value).slice(1)
|
1028
|
-
: '';
|
1029
|
-
}
|
1030
|
-
/** Clean extra whitespaces */
|
1031
|
-
static CleanUpBlanks(value) {
|
1032
|
-
return value && Tools.IsNotOnlyWhiteSpace(value)
|
1033
|
-
? String(value).replace(/\s+/g, ' ').trim()
|
1034
|
-
: '';
|
1035
|
-
}
|
1036
|
-
/** Apply title formatting */
|
1037
|
-
static ToTitle(value) {
|
1038
|
-
return (Tools.IsNotOnlyWhiteSpace(value))
|
1039
|
-
? String(value).split(' ').filter(x => x.length > 0).map(x => Strings.FirstCharToUpper(x.toLowerCase())).join(' ')
|
1040
|
-
: '';
|
1041
|
-
}
|
1042
|
-
/** Removes the last character */
|
1043
|
-
static RemoveLastChar(value) {
|
1044
|
-
return Tools.IsNotOnlyWhiteSpace(value)
|
1045
|
-
? String(value).trimEnd().slice(0, -1)
|
1046
|
-
: '';
|
1047
|
-
}
|
1048
|
-
/** Removes accents */
|
1049
|
-
static RemoveAccents(value, except = []) {
|
1050
|
-
if (Tools.IsOnlyWhiteSpace(value))
|
1051
|
-
return '';
|
1052
|
-
if (except.length > 0) {
|
1053
|
-
let index = 0;
|
1054
|
-
const mapValue = new Map();
|
1055
|
-
for (const char of String(value)) {
|
1056
|
-
mapValue.set(index++, char);
|
1057
|
-
}
|
1058
|
-
index = 0;
|
1059
|
-
const mapNormalize = new Map();
|
1060
|
-
for (const char of String(value).normalize('NFD').replace(/[\u0300-\u036f]/g, '')) {
|
1061
|
-
mapNormalize.set(index++, char);
|
1062
|
-
}
|
1063
|
-
for (const char of except) {
|
1064
|
-
for (const [index, value] of mapValue.entries()) {
|
1065
|
-
if (value === char) {
|
1066
|
-
mapNormalize.set(index, char);
|
1067
|
-
}
|
1068
|
-
}
|
1069
|
-
}
|
1070
|
-
return Array.from(mapNormalize.values()).join('');
|
1071
|
-
}
|
1072
|
-
else {
|
1073
|
-
return String(value).normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
1074
|
-
}
|
1075
|
-
}
|
1076
|
-
/** Removes special characters */
|
1077
|
-
static RemoveSpecialCharacters(value) {
|
1078
|
-
return (Tools.IsNotOnlyWhiteSpace(value))
|
1079
|
-
? String(value).replace(/[^a-zA-Z0-9áéíóúÁÉÍÓÚüÜñÑ\s]/g, '') : '';
|
1080
|
-
}
|
1081
|
-
/** Only Alphanumeric */
|
1082
|
-
static OnlyAlphanumeric(value) {
|
1083
|
-
return (Tools.IsNotOnlyWhiteSpace(value))
|
1084
|
-
? String(value).replace(/[^a-zA-Z0-9\s]/g, '') : '';
|
1085
|
-
}
|
1086
|
-
/** Only Alphanumeric */
|
1087
|
-
static OnlyNumbers(value) {
|
1088
|
-
return (Tools.IsNotOnlyWhiteSpace(value))
|
1089
|
-
? String(value).replace(/[^0-9\s]/g, '') : '';
|
1090
|
-
}
|
1091
|
-
/** Validates if both strings are equal */
|
1092
|
-
static Equals(value, value2, sensitive = false) {
|
1093
|
-
if (typeof value === null && typeof value2 === null)
|
1094
|
-
return true;
|
1095
|
-
if (typeof value === 'undefined' && typeof value2 === 'undefined')
|
1096
|
-
return true;
|
1097
|
-
if (typeof value === 'string' && typeof value2 === 'string') {
|
1098
|
-
if (!sensitive) {
|
1099
|
-
value = value.toUpperCase();
|
1100
|
-
value2 = value2.toUpperCase();
|
1101
|
-
}
|
1102
|
-
return value.length === value2.length
|
1103
|
-
&& value === value2;
|
1104
|
-
}
|
1105
|
-
return false;
|
1106
|
-
}
|
1107
|
-
}
|
1108
|
-
|
1109
1113
|
class Files {
|
1110
1114
|
static { this.EXCEL_EXTENSIONS = ['xls', 'xlsx', 'csv']; }
|
1111
1115
|
/** Get Extension File */
|