coer-elements 2.0.80 → 2.0.82
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/components/lib/coer-datebox/coer-datebox.component.d.ts +1 -1
- package/components/lib/coer-grid/coer-grid.extension.d.ts +6 -4
- package/components/lib/coer-modal/coer-modal.component.d.ts +1 -1
- package/components/lib/coer-numberbox/coer-numberbox.component.d.ts +1 -1
- package/components/lib/coer-secretbox/coer-secretbox.component.d.ts +1 -1
- package/components/lib/coer-textarea/coer-textarea.component.d.ts +1 -1
- package/components/lib/coer-textbox/coer-textbox.component.d.ts +1 -1
- package/extensions/lib/array.extension.d.ts +2 -2
- package/extensions/lib/date.extension.d.ts +61 -0
- package/extensions/lib/string.extension.d.ts +2 -0
- package/extensions/public-api.d.ts +1 -0
- package/fesm2022/coer-elements-components.mjs +26 -24
- package/fesm2022/coer-elements-components.mjs.map +1 -1
- package/fesm2022/coer-elements-extensions.mjs +91 -3
- package/fesm2022/coer-elements-extensions.mjs.map +1 -1
- package/fesm2022/coer-elements-pages.mjs +9 -8
- package/fesm2022/coer-elements-pages.mjs.map +1 -1
- package/fesm2022/coer-elements-services.mjs +1 -1
- package/fesm2022/coer-elements-services.mjs.map +1 -1
- package/fesm2022/coer-elements-tools.mjs +106 -60
- package/fesm2022/coer-elements-tools.mjs.map +1 -1
- package/package.json +1 -1
- package/styles/coer-elements.css +1 -1
- package/styles/index.scss +4 -4
- package/styles/layout-grid.scss +5 -1
- package/tools/lib/date-time.tools.d.ts +46 -32
- package/tools/lib/numbers.tools.d.ts +2 -0
- package/tools/lib/strings.tools.d.ts +2 -0
- /package/styles/{orders.scss → order.scss} +0 -0
@@ -20,21 +20,20 @@ class Numbers {
|
|
20
20
|
static IsNotNumber(value) {
|
21
21
|
return !this.IsNumber(value);
|
22
22
|
}
|
23
|
-
/**
|
24
|
-
static
|
23
|
+
/** */
|
24
|
+
static SetDecimals(value, decimals = 2) {
|
25
25
|
if (typeof value === 'string')
|
26
26
|
value = Number(value);
|
27
27
|
if (this.IsNotNumber(value))
|
28
28
|
return '0';
|
29
29
|
let valueInteger = '';
|
30
30
|
let valueDecimal = '';
|
31
|
-
value = value
|
31
|
+
value = String(value);
|
32
32
|
if (value.includes('.') || (decimals > 0)) {
|
33
33
|
valueInteger = value.includes('.') ? value.split('.')[0] : value;
|
34
34
|
if (decimals > 0) {
|
35
|
-
const PADDING = decimals - valueDecimal.length;
|
36
35
|
valueDecimal = value.includes('.') ? value.split('.')[1] : '';
|
37
|
-
for (let i = 0; i <
|
36
|
+
for (let i = 0; i < decimals; i++)
|
38
37
|
valueDecimal += '0';
|
39
38
|
valueDecimal = valueDecimal.substring(0, decimals);
|
40
39
|
valueDecimal = `.${valueDecimal}`;
|
@@ -43,19 +42,15 @@ class Numbers {
|
|
43
42
|
else {
|
44
43
|
valueInteger = value;
|
45
44
|
}
|
46
|
-
let counter = 0;
|
47
|
-
const VALUE_INTEGER_ARRAY = [];
|
48
|
-
for (const char of valueInteger.split('').reverse()) {
|
49
|
-
if (counter == 3) {
|
50
|
-
VALUE_INTEGER_ARRAY.push(',');
|
51
|
-
counter = 0;
|
52
|
-
}
|
53
|
-
VALUE_INTEGER_ARRAY.push(char);
|
54
|
-
++counter;
|
55
|
-
}
|
56
|
-
valueInteger = VALUE_INTEGER_ARRAY.reverse().join('');
|
57
45
|
return `${valueInteger}${valueDecimal}`;
|
58
46
|
}
|
47
|
+
/** Return a string with numeric format */
|
48
|
+
static GetNumericFormat(value, decimals = 0) {
|
49
|
+
const [INTEGER, DECIMAL = ''] = this.SetDecimals(value).split('.');
|
50
|
+
return decimals > 0
|
51
|
+
? `${INTEGER.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}.${DECIMAL}`
|
52
|
+
: INTEGER.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
53
|
+
}
|
59
54
|
/** Return a string with currency format */
|
60
55
|
static GetCurrencyFormat(value, symbol = '$', currency = '') {
|
61
56
|
return `${symbol}${this.GetNumericFormat(value, 2)}${currency.length > 0 ? ` ${currency}` : ''}`;
|
@@ -711,6 +706,12 @@ class Strings {
|
|
711
706
|
? String(value).split(' ').filter(x => x.length > 0).map(x => Strings.FirstCharToUpper(x.toLowerCase())).join(' ')
|
712
707
|
: '';
|
713
708
|
}
|
709
|
+
/** Remove whitespaces */
|
710
|
+
static RemoveWhiteSpaces(value) {
|
711
|
+
return Tools.IsNotOnlyWhiteSpace(value)
|
712
|
+
? String(value).replaceAll(' ', '')
|
713
|
+
: '';
|
714
|
+
}
|
714
715
|
/** Removes the last character */
|
715
716
|
static RemoveLastChar(value) {
|
716
717
|
return Tools.IsNotOnlyWhiteSpace(value)
|
@@ -784,17 +785,22 @@ class Dates {
|
|
784
785
|
[1, 'Jan'], [2, 'Feb'], [3, 'Mar'], [4, 'Apr'], [5, 'May'], [6, 'Jun'],
|
785
786
|
[7, 'Jul'], [8, 'Aug'], [9, 'Sep'], [10, 'Oct'], [11, 'Nov'], [12, 'Dec'],
|
786
787
|
]); }
|
787
|
-
/**
|
788
|
+
/** */
|
788
789
|
static GetOffset() {
|
789
790
|
return -(new Date().getTimezoneOffset());
|
790
791
|
}
|
791
792
|
/** */
|
793
|
+
static GetLastDay(date) {
|
794
|
+
const DATE = this._CleanDate(date);
|
795
|
+
return new Date(DATE.getFullYear(), DATE.getMonth() + 1, 0).getDate();
|
796
|
+
}
|
797
|
+
/** */
|
792
798
|
static IsValidDate(date) {
|
793
799
|
return !isNaN(new Date(date).getTime());
|
794
800
|
}
|
795
|
-
/**
|
796
|
-
static
|
797
|
-
return
|
801
|
+
/** */
|
802
|
+
static GetCurrentDate() {
|
803
|
+
return new Date();
|
798
804
|
}
|
799
805
|
/** */
|
800
806
|
static _CleanDate(date) {
|
@@ -806,16 +812,16 @@ class Dates {
|
|
806
812
|
else
|
807
813
|
return date;
|
808
814
|
}
|
809
|
-
/**
|
815
|
+
/** */
|
810
816
|
static ToLocalZone(utcDate) {
|
811
|
-
return
|
817
|
+
return new Date(new Date(utcDate).getTime() + this.GetOffset() * 60000);
|
812
818
|
}
|
813
|
-
/**
|
819
|
+
/** */
|
814
820
|
static ToUTC(date) {
|
815
|
-
return
|
821
|
+
return new Date(new Date(date).getTime() - this.GetOffset() * 60000);
|
816
822
|
}
|
817
823
|
/** YYYY-MM-DD HH:mm:ss */
|
818
|
-
static
|
824
|
+
static ToFormatDB(date) {
|
819
825
|
const DATE = this._CleanDate(date);
|
820
826
|
return `${DATE.getFullYear()}` + '-'
|
821
827
|
+ `${DATE.getMonth() + 1}`.padStart(2, '0') + '-'
|
@@ -846,7 +852,7 @@ class Dates {
|
|
846
852
|
+ `${DATE.getDate()}`.padStart(2, '0') + ' ';
|
847
853
|
}
|
848
854
|
/** */
|
849
|
-
static
|
855
|
+
static ToFormatDate(date, format) {
|
850
856
|
switch (format || Tools.AvoidNull(appSettings?.dateTime?.format, 'string')) {
|
851
857
|
case 'DMY': return this._GetFormatDateDMY(date);
|
852
858
|
case 'YMD': return this._GetFormatDateYMD(date);
|
@@ -854,50 +860,50 @@ class Dates {
|
|
854
860
|
}
|
855
861
|
}
|
856
862
|
/** */
|
857
|
-
static
|
863
|
+
static ToFormatDateTime(date, ampm = true, format) {
|
858
864
|
const DATE = this._CleanDate(date);
|
859
865
|
if (ampm) {
|
860
866
|
let hours = DATE.getHours();
|
861
867
|
const AM_PM = hours >= 12 ? 'pm' : 'am';
|
862
868
|
hours = hours % 12;
|
863
869
|
hours = hours === 0 ? 12 : hours;
|
864
|
-
return `${this.
|
870
|
+
return `${this.ToFormatDate(DATE, format)}` + ' at '
|
865
871
|
+ `${hours}`.padStart(2, '0') + ':'
|
866
872
|
+ `${DATE.getMinutes()}`.padStart(2, '0') + ' '
|
867
873
|
+ `${AM_PM}`;
|
868
874
|
}
|
869
875
|
else {
|
870
|
-
return `${this.
|
876
|
+
return `${this.ToFormatDate(DATE, format)}` + ' at '
|
871
877
|
+ `${DATE.getHours()}`.padStart(2, '0') + ':'
|
872
878
|
+ `${DATE.getMinutes()}`.padStart(2, '0') + ' ';
|
873
879
|
}
|
874
880
|
}
|
875
|
-
/**
|
881
|
+
/** */
|
876
882
|
static AddMilliseconds(date, milliseconds) {
|
877
883
|
return new Date(this._CleanDate(date).getTime() + milliseconds);
|
878
884
|
}
|
879
|
-
/**
|
880
|
-
static AddSeconds(date, seconds) {
|
885
|
+
/** */
|
886
|
+
static AddSeconds(date, seconds = 1) {
|
881
887
|
return this.AddMilliseconds(date, seconds * 1000);
|
882
888
|
}
|
883
|
-
/**
|
884
|
-
static AddMinutes(date, minutes) {
|
889
|
+
/** */
|
890
|
+
static AddMinutes(date, minutes = 1) {
|
885
891
|
return this.AddMilliseconds(date, minutes * 60 * 1000);
|
886
892
|
}
|
887
|
-
/**
|
888
|
-
static
|
893
|
+
/** */
|
894
|
+
static AddHours(date, hours = 1) {
|
889
895
|
return this.AddMilliseconds(date, hours * 60 * 60 * 1000);
|
890
896
|
}
|
891
897
|
/** Add days */
|
892
|
-
static
|
898
|
+
static AddDays(date, days = 1) {
|
893
899
|
return this.AddMilliseconds(date, days * 24 * 60 * 60 * 1000);
|
894
900
|
}
|
895
|
-
/** Add
|
896
|
-
static
|
901
|
+
/** Add weeks */
|
902
|
+
static AddWeeks(date, weeks = 1) {
|
897
903
|
return this.AddMilliseconds(date, weeks * 7 * 24 * 60 * 60 * 1000);
|
898
904
|
}
|
899
905
|
/** Add months */
|
900
|
-
static
|
906
|
+
static AddMonths(date, months = 1) {
|
901
907
|
const DATE = this._CleanDate(date);
|
902
908
|
const DATE_UPDATED = new Date(DATE.getFullYear(), (DATE.getMonth() + months), 1);
|
903
909
|
DATE_UPDATED.setDate(Math.min(DATE.getDate(), new Date(DATE_UPDATED.getFullYear(), (DATE_UPDATED.getMonth() + 1), 0).getDate()));
|
@@ -905,51 +911,91 @@ class Dates {
|
|
905
911
|
return DATE_UPDATED;
|
906
912
|
}
|
907
913
|
/** Add years */
|
908
|
-
static
|
914
|
+
static AddYears(date, years = 1) {
|
909
915
|
const DATE = this._CleanDate(date);
|
910
916
|
const DATE_UPDATED = new Date((DATE.getFullYear() + years), DATE.getMonth(), 1);
|
911
917
|
DATE_UPDATED.setDate(Math.min(DATE.getDate(), new Date(DATE_UPDATED.getFullYear(), DATE_UPDATED.getMonth() + 1, 0).getDate()));
|
912
918
|
DATE_UPDATED.setHours(DATE.getHours(), DATE.getMinutes(), DATE.getSeconds(), DATE.getMilliseconds());
|
913
919
|
return DATE_UPDATED;
|
914
920
|
}
|
915
|
-
/**
|
916
|
-
static
|
921
|
+
/** */
|
922
|
+
static SetMillisecond(date, millisecond = 0) {
|
917
923
|
const DATE = this._CleanDate(date);
|
918
|
-
if (
|
919
|
-
|
924
|
+
if (millisecond < 0 || millisecond >= 1000) {
|
925
|
+
millisecond = DATE.getMilliseconds();
|
920
926
|
}
|
921
|
-
DATE.
|
922
|
-
return
|
927
|
+
DATE.setMilliseconds(millisecond);
|
928
|
+
return DATE;
|
923
929
|
}
|
924
|
-
/**
|
925
|
-
static
|
930
|
+
/** */
|
931
|
+
static SetSecond(date, second = 0) {
|
932
|
+
const DATE = this._CleanDate(date);
|
933
|
+
if (second < 0 || second >= 60) {
|
934
|
+
second = DATE.getSeconds();
|
935
|
+
}
|
936
|
+
DATE.setSeconds(second);
|
937
|
+
return DATE;
|
938
|
+
}
|
939
|
+
/** */
|
940
|
+
static SetMinute(date, minute = 0) {
|
926
941
|
const DATE = this._CleanDate(date);
|
927
942
|
if (minute < 0 || minute >= 60) {
|
928
943
|
minute = DATE.getMinutes();
|
929
944
|
}
|
930
945
|
DATE.setMinutes(minute, DATE.getSeconds());
|
931
|
-
return
|
946
|
+
return DATE;
|
932
947
|
}
|
933
|
-
/**
|
934
|
-
static
|
948
|
+
/** */
|
949
|
+
static SetHour(date, hour = 0) {
|
935
950
|
const DATE = this._CleanDate(date);
|
936
|
-
if (
|
937
|
-
|
951
|
+
if (hour < 0 || hour >= 24) {
|
952
|
+
hour = DATE.getHours();
|
938
953
|
}
|
939
|
-
DATE.
|
940
|
-
return
|
954
|
+
DATE.setHours(hour, DATE.getMinutes(), DATE.getSeconds());
|
955
|
+
return DATE;
|
941
956
|
}
|
942
|
-
/** Set 00:00:00
|
957
|
+
/** Set 00:00:00 */
|
943
958
|
static SetFirstHour(date) {
|
944
959
|
const DATE = this._CleanDate(date);
|
945
960
|
DATE.setHours(0, 0, 0);
|
946
|
-
return
|
961
|
+
return DATE;
|
947
962
|
}
|
948
|
-
/** Set 23:59:59
|
963
|
+
/** Set 23:59:59 */
|
949
964
|
static SetLastHour(date) {
|
950
965
|
const DATE = this._CleanDate(date);
|
951
966
|
DATE.setHours(23, 59, 59);
|
952
|
-
return
|
967
|
+
return DATE;
|
968
|
+
}
|
969
|
+
/** */
|
970
|
+
static SetDay(date, day = 1) {
|
971
|
+
const DATE = this._CleanDate(date);
|
972
|
+
if (day < 1 || day > this.GetLastDay(DATE)) {
|
973
|
+
day = DATE.getDate();
|
974
|
+
}
|
975
|
+
DATE.setDate(day);
|
976
|
+
return DATE;
|
977
|
+
}
|
978
|
+
/** */
|
979
|
+
static SetFirstDay(date) {
|
980
|
+
return this.SetDay(date, 1);
|
981
|
+
}
|
982
|
+
/** */
|
983
|
+
static SetLastDay(date) {
|
984
|
+
return this.SetDay(date, this.GetLastDay(date));
|
985
|
+
}
|
986
|
+
/** */
|
987
|
+
static GetDiffNow(date, unit = 'minutes') {
|
988
|
+
return this.GetDiff(this.GetCurrentDate(), date, unit);
|
989
|
+
}
|
990
|
+
/** */
|
991
|
+
static GetDiff(fromDate, toDate, unit = 'minutes') {
|
992
|
+
switch (unit) {
|
993
|
+
case 'milliseconds': return Number(Numbers.SetDecimals(this._CleanDate(fromDate).getTime() - this._CleanDate(toDate).getTime(), 0));
|
994
|
+
case 'seconds': return Number(Numbers.SetDecimals((this._CleanDate(fromDate).getTime() - this._CleanDate(toDate).getTime()) / 1000, 0));
|
995
|
+
case 'minutes': return Number(Numbers.SetDecimals((this._CleanDate(fromDate).getTime() - this._CleanDate(toDate).getTime()) / (1000 * 60), 0));
|
996
|
+
case 'hours': return Number(Numbers.SetDecimals((this._CleanDate(fromDate).getTime() - this._CleanDate(toDate).getTime()) / (1000 * 60 * 60), 0));
|
997
|
+
case 'days': return Number(Numbers.SetDecimals((this._CleanDate(fromDate).getTime() - this._CleanDate(toDate).getTime()) / (1000 * 60 * 60 * 24), 0));
|
998
|
+
}
|
953
999
|
}
|
954
1000
|
}
|
955
1001
|
|