ngx-sfc-common 0.0.30 → 0.0.32

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.
@@ -593,1068 +593,1146 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImpor
593
593
  }] } });
594
594
 
595
595
  /**
596
- * Set minutes for date
597
- * @param date Date value
598
- * @param minute Minute value
599
- * @returns Date with minute value
596
+ * Return true if string has value(not empty string)
597
+ * @param value String value to check
598
+ * @returns True if string is not null and defined(not empty string)
600
599
  */
601
- function setMinutes(date, minute) {
602
- const result = new Date(date);
603
- result.setMinutes(minute);
604
- return result;
600
+ function isNullOrEmptyString(value) {
601
+ return !isDefined(value) || value === CommonConstants.EMPTY_STRING;
605
602
  }
606
603
  /**
607
- * Set hours for date
608
- * @param date Date value
609
- * @param hour Hour value
610
- * @returns Date with hour value
604
+ * Return true if value contains includeValue
605
+ * @param value String value to check
606
+ * @param includeValue Value to check if it include
607
+ * @returns True if value contains includeValue
611
608
  */
612
- function setHours(date, hour) {
613
- const result = new Date(date);
614
- result.setHours(hour);
615
- return result;
609
+ function contains(value, includeValue) {
610
+ return !isNullOrEmptyString(value) && !isNullOrEmptyString(includeValue)
611
+ ? value.toLowerCase()
612
+ .includes(includeValue.toLowerCase())
613
+ : false;
616
614
  }
617
615
  /**
618
- * Set day for date value
619
- * @param date Date value
620
- * @param dayNumber Day number
621
- * @returns Date with day number
616
+ * Return trimed value
617
+ * @param value Value for trim modification
618
+ * @returns Trimed value
622
619
  */
623
- function setDay(date, dayNumber) {
624
- const nextDate = new Date(date);
625
- nextDate.setDate(dayNumber);
626
- return nextDate;
627
- }
620
+ function trim(value) {
621
+ return isNullOrEmptyString(value) ? value : value.replace(/\s/g, '');
622
+ }
623
+
628
624
  /**
629
- * Set year for date
630
- * @param date Date value
631
- * @param year Year value
632
- * @returns Date with year value
625
+ * Return true if collection not empty
626
+ * @param collection Array of items
627
+ * @returns True if collection not empty
633
628
  */
634
- function setYear(date, year) {
635
- const result = new Date(date);
636
- result.setFullYear(year);
637
- return result;
629
+ function any(collection) {
630
+ return isDefined(collection) && collection.length > 0;
638
631
  }
639
632
  /**
640
- * Set seconds for date
641
- * @param date Date value
642
- * @param value Seconds value
643
- * @returns Date with minute value
633
+ * Return true if collection has such value
634
+ * @param collection Array of items
635
+ * @param value Value to check
636
+ * @returns True if found value in collection
644
637
  */
645
- function setSeconds(date, value) {
646
- const result = new Date(date);
647
- result.setSeconds(value);
648
- return result;
638
+ function hasItem(collection, value) {
639
+ return any(collection)
640
+ && collection.findIndex(item => item === value) !== CommonConstants.NOT_FOUND_INDEX;
649
641
  }
650
642
  /**
651
- * Set milliseconds for date
652
- * @param date Date value
653
- * @param value Milliseconds value
654
- * @returns Date with minute value
643
+ * Return true if collection has such value by predicate function
644
+ * @param collection Array of items
645
+ * @param predicate Function to define check logic
646
+ * @returns True if found value in collection
655
647
  */
656
- function setMilliseconds(date, value) {
657
- const result = new Date(date);
658
- result.setMilliseconds(value);
659
- return result;
648
+ function hasItemBy(collection, predicate) {
649
+ return any(collection) && collection.findIndex(predicate) !== CommonConstants.NOT_FOUND_INDEX;
660
650
  }
661
651
  /**
662
- * Set 0 for seconds and milliseconds of date
663
- * @param date Date value
664
- * @returns Date with minute value
652
+ * Return true if collection of objects has such value as object
653
+ * @param collection Array of objects
654
+ * @param property Property name
655
+ * @param value Value to check
656
+ * @returns True if found value in collection
665
657
  */
666
- function setDefaultSecondsAndMiliseconds(date) {
667
- const result = new Date(date);
668
- result.setSeconds(0);
669
- result.setMilliseconds(0);
670
- return result;
658
+ function hasObjectItem(collection, // TODO <-- Array<T>
659
+ property, value) {
660
+ return any(collection)
661
+ && collection.findIndex(item => item.hasOwnProperty(property)
662
+ && item[property] === value) !== CommonConstants.NOT_FOUND_INDEX;
671
663
  }
672
664
  /**
673
- * Get next date
674
- * @param date Date value
675
- * @returns Next date
665
+ * Return true if first collection has item in second collection
666
+ * @param collection1 Array of objects where search
667
+ * @param collection2 Array of objects where try to find
668
+ * @returns
676
669
  */
677
- function getNextDate(date) {
678
- const nextDate = new Date(date);
679
- nextDate.setDate(date.getDate() + 1);
680
- return nextDate;
670
+ function hasAnyItem(collection1, collection2) {
671
+ return collection1.some(item => collection2.includes(item));
681
672
  }
682
673
  /**
683
- * Get previous date
684
- * @param date Date value
685
- * @returns Previous date
674
+ * Return value from collection by predicate function
675
+ * @param collection Array of items
676
+ * @param predicate Function to define search logic
677
+ * @returns Value from collection
686
678
  */
687
- function getPreviousDate(date) {
688
- const nextDate = new Date(date);
689
- nextDate.setDate(date.getDate() - 1);
690
- return nextDate;
679
+ function firstOrDefault(collection, predicate) {
680
+ return any(collection) ? collection?.find(predicate) : undefined;
691
681
  }
692
682
  /**
693
- * Get next month as date
694
- * @param date Date value
695
- * @returns Next month as date
683
+ * Return first item from collection
684
+ * @param collection Array of items
685
+ * @returns First value from collection
696
686
  */
697
- function getNextMonth(date) {
698
- const nextMonth = new Date(date);
699
- nextMonth.setMonth(date.getMonth() + 1);
700
- return nextMonth;
687
+ function firstItem(collection) {
688
+ return any(collection) ? collection[0] : null;
701
689
  }
702
690
  /**
703
- * Get previous month as date
704
- * @param date Date value
705
- * @returns Previous month as date
691
+ * Return last item from collection
692
+ * @param collection Array of items
693
+ * @returns Last value from collection
706
694
  */
707
- function getPreviousMonth(date) {
708
- const prevMonth = new Date(date);
709
- prevMonth.setMonth(date.getMonth() - 1);
710
- return prevMonth;
695
+ function lastItem(collection) {
696
+ return any(collection) ? collection[collection.length - 1] : null;
711
697
  }
712
698
  /**
713
- * Get next year as date
714
- * @param date Date value
715
- * @returns Next year as date
699
+ * Return True if all values match predicate function
700
+ * @param collection Array of objects
701
+ * @param predicate Function to define check logic
702
+ * @returns True if all values match predicate
716
703
  */
717
- function getNextYear(date) {
718
- const nextYear = new Date(date);
719
- nextYear.setFullYear(date.getFullYear() + 1);
720
- return nextYear;
704
+ function all(collection, predicate) {
705
+ return any(collection) ? collection.filter(predicate).length == collection.length : false;
721
706
  }
722
707
  /**
723
- * Get previous year as date
724
- * @param date Date value
725
- * @returns Previous year as date
708
+ * Return count by predicate
709
+ * @param collection Array of objects
710
+ * @param predicate Function to define check logic
711
+ * @returns Items count
726
712
  */
727
- function getPreviousYear(date) {
728
- const prevYear = new Date(date);
729
- prevYear.setFullYear(date.getFullYear() - 1);
730
- return prevYear;
713
+ function count(collection, predicate) {
714
+ return collection.filter(predicate).length;
731
715
  }
732
716
  /**
733
- * Return first day of month as date from date value
734
- * @param date Date value
735
- * @returns First day of month as date
717
+ * Return items from collection by predicate function
718
+ * @param collection Array of items
719
+ * @param predicate Function to define search logic
720
+ * @returns Values from collection
736
721
  */
737
- function getFirstDayOfMonth(date) {
738
- if (isDefined(date) && date instanceof Date) {
739
- const year = date.getFullYear(), month = date.getMonth();
740
- return new Date(year, month, 1);
741
- }
742
- return date;
722
+ function where(collection, predicate) {
723
+ return any(collection) ? collection.filter(predicate) : null;
743
724
  }
744
725
  /**
745
- * Return last day of month as date from date value
746
- * @param date Date value
747
- * @returns Last day of month as date
726
+ * Return sliced collection by page number and page size
727
+ * @param collection Array of items
728
+ * @param page Page number
729
+ * @param size Page size
730
+ * @returns Sliced collection
748
731
  */
749
- function getLastDayOfMonth(date) {
750
- if (isDefined(date) && date instanceof Date) {
751
- const year = date.getFullYear(), month = date.getMonth();
752
- return new Date(year, month + 1, 0);
732
+ function skip(collection, page, size) {
733
+ if (any(collection)) {
734
+ let start = (page - 1) * size;
735
+ return collection.slice(start, start + size);
753
736
  }
754
- return date;
737
+ return collection;
755
738
  }
756
- /**
757
- * Return first day of year as date from date value
758
- * @param date Date value
759
- * @returns First day of year as date
760
- */
761
- function getFirstDayOfYear(date) {
762
- if (isDefined(date) && date instanceof Date) {
763
- return new Date(date.getFullYear(), 0, 1);
739
+ function sort(collection, direction = SortingDirection.Ascending) {
740
+ if (any(collection)) {
741
+ return direction == SortingDirection.Ascending
742
+ ? collection.sort((a, b) => a - b)
743
+ : collection.sort((a, b) => b - a);
764
744
  }
765
- return date;
745
+ return collection;
766
746
  }
767
747
  /**
768
- * Return last day of year as date from date value
769
- * @param date Date value
770
- * @returns Last day of year as date
748
+ * Return sorted collection of objects by property
749
+ * @param collection Array of items
750
+ * @param property Property name
751
+ * @param direction Sorting direction
752
+ * @returns Sorted collection
771
753
  */
772
- function getLastDayOfYear(date) {
773
- if (isDefined(date) && date instanceof Date) {
774
- return new Date(date.getFullYear(), 12, 0);
754
+ function sortBy(collection, property, direction) {
755
+ if (any(collection)) {
756
+ let _sortFunc = (a, b) => (t1, t2) => (a[property] > b[property] ? t1 : t2);
757
+ return direction == SortingDirection.Ascending
758
+ ? collection.sort((a, b) => _sortFunc(a, b)(1, -1))
759
+ : collection.sort((a, b) => _sortFunc(a, b)(-1, 1));
775
760
  }
776
- return date;
761
+ return collection;
777
762
  }
778
763
  /**
779
- * Return first day of month as date
780
- * @param year Year value
781
- * @param month Month value
782
- * @returns First day of month
783
- */
784
- function getFirstDayOfMonthByYearAndMonth(year, month) {
785
- return new Date(year, month, 1);
786
- }
787
- /**
788
- * Return last day of month as date
789
- * @param year Year value
790
- * @param month Month value
791
- * @returns Last day of month
764
+ * Return sorted collection of objects by path
765
+ * @param collection Array of items
766
+ * @param path Path to property
767
+ * @param direction Sorting direction
768
+ * @returns Sorted collection
792
769
  */
793
- function getLastDayOfMonthByYearAndMonth(year, month) {
794
- return new Date(year, month + 1, 0);
770
+ function sortByPath(collection, path, direction) {
771
+ if (any(collection)) {
772
+ if (isNullOrEmptyString(path))
773
+ throw new Error('Collection utils | Sort By Path function --> Path is empty.');
774
+ const pathParts = path.split('.');
775
+ if (!any(pathParts))
776
+ throw new Error('Collection utils | Sort By Path function --> Path is incorrect.');
777
+ const partsLength = pathParts.length;
778
+ collection.sort((a, b) => {
779
+ var i = 0;
780
+ while (i < partsLength) {
781
+ a = a[pathParts[i]];
782
+ b = b[pathParts[i]];
783
+ i++;
784
+ }
785
+ return direction == SortingDirection.Ascending
786
+ ? a >= b ? 1 : -1
787
+ : a > b ? -1 : 1;
788
+ });
789
+ return collection;
790
+ }
791
+ return collection;
795
792
  }
796
793
  /**
797
- * Return week number in month from date value
798
- * @param date Date value
799
- * @returns Week number
794
+ * Return collection without matches
795
+ * @param collection Array of items
796
+ * @returns Collection without matches
800
797
  */
801
- function getWeeksNumberInMonth(date) {
802
- const firstOfMonth = getFirstDayOfMonth(date), lastOfMonth = getLastDayOfMonth(date), used = firstOfMonth.getDay() + lastOfMonth.getDate();
803
- return Math.ceil(used / DateTimeConstants.DAYS_IN_WEEK);
798
+ function distinct(collection) {
799
+ return any(collection)
800
+ ? collection.filter((value, index, self) => self.indexOf(value) === index)
801
+ : collection;
804
802
  }
805
803
  /**
806
- * Return true if first and second date are equal
807
- * @param date1 First date value
808
- * @param date2 Second date value
809
- * @returns True if first and second date are equal
804
+ * Return sum value from collection items by map function
805
+ * @param collection Array of items
806
+ * @param select Map function
807
+ * @returns Sum value of colection items
810
808
  */
811
- function isEqualDates(date1, date2) {
812
- const date1Value = new Date(date1), date2Value = new Date(date2);
813
- date1Value.setHours(0, 0, 0, 0);
814
- date2Value.setHours(0, 0, 0, 0);
815
- return date1Value.getTime() === date2Value.getTime();
809
+ function sum(collection, select) {
810
+ return any(collection)
811
+ ? collection
812
+ .map(select)
813
+ .reduce((a, b) => { return a + b; }, 0)
814
+ : 0;
816
815
  }
817
816
  /**
818
- * Return true if first and second datetime are equal
819
- * @param date1 First datetime value
820
- * @param date2 Second datetime value
821
- * @returns True if first and second datetime are equal
817
+ * Return max value from collection items by map function
818
+ * @param collection Array of items
819
+ * @param select Map function
820
+ * @returns Max value of collection items
822
821
  */
823
- function isEqualDateTimes(date1, date2) {
824
- const date1Value = new Date(date1), date2Value = new Date(date2);
825
- return date1Value.getTime() === date2Value.getTime();
822
+ function max(collection, select) {
823
+ if (any(collection))
824
+ return Math.max(...collection.map(select));
825
+ throw new Error('Collection utils | Max function --> Collection is empty.');
826
826
  }
827
827
  /**
828
- * Return true if first date greater than second date
829
- * @param date1 First date value
830
- * @param date2 Second date value
831
- * @returns True if first date greater than second date
828
+ * Delete items from collection by predicate
829
+ * @param collection Array of items
830
+ * @param predicate Function to define remove logic
832
831
  */
833
- function isDateGreat(date1, date2) {
834
- return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
835
- > new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
832
+ function remove(collection, predicate) {
833
+ var i = collection.length;
834
+ while (i--) {
835
+ if (predicate(collection[i])) {
836
+ collection.splice(i, 1);
837
+ }
838
+ }
836
839
  }
837
840
  /**
838
- * Return true if first date greater or equal to second date
839
- * @param date1 First date value
840
- * @param date2 Second date value
841
- * @returns True if first date greater or equal to second date
841
+ * Add item to collection
842
+ * @param collection Array of items
843
+ * @param item New item
844
+ * @param predicate Function to define if allowed to add new item
845
+ * @returns True if successfully added
842
846
  */
843
- function isDateGreatOrEqual(date1, date2) {
844
- return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
845
- >= new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
847
+ function addItem(collection, item, predicate = null) {
848
+ if (!isDefined(collection))
849
+ collection = new Array();
850
+ if (isDefined(predicate) && predicate(item))
851
+ return false;
852
+ collection.push(item);
853
+ return true;
846
854
  }
847
855
  /**
848
- * Return true if first date time greater than second date time
849
- * @param date1 First date time value
850
- * @param date2 Second date time value
851
- * @returns True if first date time greater than second date time
856
+ * Delete item from collection
857
+ * @param collection Array of items
858
+ * @param item Item to delete
859
+ * @returns True if successfully removed
852
860
  */
853
- function isDateTimeGreat(date1, date2) {
854
- return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(), date1.getHours(), date1.getMinutes())
855
- > new Date(date2.getFullYear(), date2.getMonth(), date2.getDate(), date2.getHours(), date2.getMinutes());
861
+ function removeItem(collection, item) {
862
+ if (isDefined(item) && hasItem(collection, item)) {
863
+ collection.splice(collection.indexOf(item), 1);
864
+ return true;
865
+ }
866
+ return false;
856
867
  }
857
868
  /**
858
- * Return true if first date time greater or equal to second date time
859
- * @param date1 First date time value
860
- * @param date2 Second date time value
861
- * @returns True if first date time greater or equal to second date time
869
+ * Delete item from collection by predicate
870
+ * @param collection Array of items
871
+ * @param predicate Function to define remove logic
872
+ * @returns True if successfully removed
862
873
  */
863
- function isDateTimeGreatOrEqual(date1, date2) {
864
- return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(), date1.getHours(), date1.getMinutes())
865
- >= new Date(date2.getFullYear(), date2.getMonth(), date2.getDate(), date2.getHours(), date2.getMinutes());
874
+ function removeItemBy(collection, predicate) {
875
+ const foundItem = firstOrDefault(collection, predicate);
876
+ if (isDefined(foundItem)) {
877
+ collection.splice(collection.indexOf(foundItem), 1);
878
+ return true;
879
+ }
880
+ return false;
866
881
  }
867
882
  /**
868
- * Return true if first time greater or equal to second time
869
- * @param date1 First date time value
870
- * @param date2 Second date time value
871
- * @returns True if first time greater or equal to second time
883
+ * Update item in collection by predicate
884
+ * @param collection Array of items
885
+ * @param predicate Function to define item for deleting
886
+ * @returns True if successfully removed
872
887
  */
873
- function isTimeGreatOrEqual(date1, date2) {
874
- return new Date(0, 0, 0, date1.getHours(), date1.getMinutes())
875
- >= new Date(0, 0, 0, date2.getHours(), date2.getMinutes());
888
+ function updateItemBy(collection, predicate, newItem) {
889
+ const itemIndex = collection.findIndex(predicate);
890
+ if (itemIndex !== CommonConstants.NOT_FOUND_INDEX) {
891
+ const result = collection.slice(0);
892
+ result[itemIndex] = {
893
+ ...collection[itemIndex],
894
+ ...newItem
895
+ };
896
+ return result;
897
+ }
898
+ return null;
876
899
  }
877
900
  /**
878
- * Return true if first time less or equal to second time
879
- * @param date1 First date time value
880
- * @param date2 Second date time value
881
- * @returns True if first time less or equal to second time
901
+ * Return collection or empty if collection is not defined
902
+ * @param collection Array of items
903
+ * @returns Collection or empty
882
904
  */
883
- function isDateTimeLessOrEqual(date1, date2) {
884
- return new Date(0, 0, 0, date1.getHours(), date1.getMinutes())
885
- <= new Date(0, 0, 0, date2.getHours(), date2.getMinutes());
905
+ function getCollectionOrEmpty(collection) {
906
+ return isDefined(collection) ? collection : [];
886
907
  }
887
908
  /**
888
- * Return true if first time less or equal to second time
889
- * @param date1 First date time value
890
- * @param date2 Second date time value
891
- * @returns True if first time less or equal to second time
909
+ * Check if arrays are equal
910
+ * @param a First array
911
+ * @param b Second array
912
+ * @returns True if arrays are equal
892
913
  */
893
- function isTimeLessOrEqual(date1, date2) {
894
- return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(), date1.getHours(), date1.getMinutes())
895
- <= new Date(date2.getFullYear(), date2.getMonth(), date2.getDate(), date2.getHours(), date2.getMinutes());
896
- }
914
+ function isArraysEquals(a, b) {
915
+ if (a.length !== b.length)
916
+ return false;
917
+ a.sort();
918
+ b.sort();
919
+ for (let i = 0; i < a.length; i++) {
920
+ if (a[i] !== b[i])
921
+ return false;
922
+ }
923
+ return true;
924
+ }
925
+
897
926
  /**
898
- * Convert UTC date to local
927
+ * Set minutes for date
899
928
  * @param date Date value
900
- * @returns Locale date
929
+ * @param minute Minute value
930
+ * @returns Date with minute value
901
931
  */
902
- function convertUTCDateToLocalDate(date) {
903
- return new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
932
+ function setMinutes(date, minute) {
933
+ const result = new Date(date);
934
+ result.setMinutes(minute);
935
+ return result;
904
936
  }
905
937
  /**
906
- * Convert Json representation of timestamp to date value
907
- * @param timestamp Timestamp for example - 12:23:45
908
- * @returns Date value
938
+ * Set hours for date
939
+ * @param date Date value
940
+ * @param hour Hour value
941
+ * @returns Date with hour value
909
942
  */
910
- function convertTimestampToDate(timestamp) {
911
- const tempTime = timestamp.split(":"), result = new Date();
912
- result.setHours(+tempTime[0]);
913
- result.setMinutes(+tempTime[1]);
914
- result.setSeconds(+tempTime[2]);
943
+ function setHours(date, hour) {
944
+ const result = new Date(date);
945
+ result.setHours(hour);
915
946
  return result;
916
947
  }
917
948
  /**
918
- * Convert Date object to timestamp string
949
+ * Set day for date value
919
950
  * @param date Date value
920
- * @param locale Locale value
921
- * @returns String representation of date value, for example - 12:23
951
+ * @param dayNumber Day number
952
+ * @returns Date with day number
922
953
  */
923
- function convertDateToTimestamp(date, locale = DateTimeConstants.DEFAULT_LOCALE) {
924
- return `${formatDate(date, 'HH', locale)}:${formatDate(date, 'mm', locale)}`;
954
+ function setDay(date, dayNumber) {
955
+ const nextDate = new Date(date);
956
+ nextDate.setDate(dayNumber);
957
+ return nextDate;
925
958
  }
926
959
  /**
927
- * Get age from
928
- * @param birthdate Date of birth
929
- * @returns Age
960
+ * Set year for date
961
+ * @param date Date value
962
+ * @param year Year value
963
+ * @returns Date with year value
930
964
  */
931
- function getAge(birthdate) {
932
- if (!birthdate)
933
- return null;
934
- const now = new Date();
935
- let age = now.getFullYear() - birthdate.getFullYear();
936
- const monthDifference = now.getMonth() - birthdate.getMonth();
937
- if (monthDifference < 0 || (monthDifference === 0 && now.getDate() < birthdate.getDate())) {
938
- age--;
939
- }
940
- return age;
941
- }
942
-
965
+ function setYear(date, year) {
966
+ const result = new Date(date);
967
+ result.setFullYear(year);
968
+ return result;
969
+ }
943
970
  /**
944
- * Return true if value defined
945
- * @param value Value to check
946
- * @returns True if value is not null and defined
971
+ * Set seconds for date
972
+ * @param date Date value
973
+ * @param value Seconds value
974
+ * @returns Date with minute value
947
975
  */
948
- function isDefined(value) {
949
- return value !== undefined && value !== null;
976
+ function setSeconds(date, value) {
977
+ const result = new Date(date);
978
+ result.setSeconds(value);
979
+ return result;
950
980
  }
951
981
  /**
952
- * Return true if value is object
953
- * @param value Value to check
954
- * @returns True if value is object
982
+ * Set milliseconds for date
983
+ * @param date Date value
984
+ * @param value Milliseconds value
985
+ * @returns Date with minute value
955
986
  */
956
- function isObject(value) {
957
- return (isDefined(value) && typeof value === 'object'
958
- && !Array.isArray(value)
959
- && !(value instanceof Date || value instanceof File));
987
+ function setMilliseconds(date, value) {
988
+ const result = new Date(date);
989
+ result.setMilliseconds(value);
990
+ return result;
960
991
  }
961
992
  /**
962
- * Return true if data is observable
963
- * @param data Object to check
964
- * @returns True if data is observable
993
+ * Set 0 for seconds and milliseconds of date
994
+ * @param date Date value
995
+ * @returns Date with minute value
965
996
  */
966
- function isAsyncData(data) {
967
- return data instanceof Observable;
997
+ function setDefaultSecondsAndMiliseconds(date) {
998
+ const result = new Date(date);
999
+ result.setSeconds(0);
1000
+ result.setMilliseconds(0);
1001
+ return result;
968
1002
  }
969
1003
  /**
970
- * Return extended object with new property
971
- * @param obj Object to extend by property
972
- * @param property New property name
973
- * @param value Value for new property
974
- * @returns Extended object with new property
1004
+ * Get next date
1005
+ * @param date Date value
1006
+ * @returns Next date
975
1007
  */
976
- function addPropertyToObject(obj, property, value = null) {
977
- if (isDefined(property) && !obj.hasOwnProperty(property)) {
978
- let newObj = {};
979
- newObj[property] = value;
980
- obj = { ...obj, ...newObj };
981
- }
982
- return obj;
1008
+ function getNextDate(date) {
1009
+ const nextDate = new Date(date);
1010
+ nextDate.setDate(date.getDate() + 1);
1011
+ return nextDate;
983
1012
  }
984
1013
  /**
985
- * Remove property from object
986
- * @param obj Object for removing property
987
- * @param property Property name to remove
1014
+ * Get previous date
1015
+ * @param date Date value
1016
+ * @returns Previous date
988
1017
  */
989
- function removePropertyFromObject(obj, property) {
990
- if (obj.hasOwnProperty(property)) {
991
- delete obj[property];
992
- }
1018
+ function getPreviousDate(date) {
1019
+ const nextDate = new Date(date);
1020
+ nextDate.setDate(date.getDate() - 1);
1021
+ return nextDate;
993
1022
  }
994
1023
  /**
995
- * Deep merge object with others
996
- * @param target Object to merge
997
- * @param sources Objects to be merged with target
998
- * @returns Merged object
1024
+ * Get next month as date
1025
+ * @param date Date value
1026
+ * @returns Next month as date
999
1027
  */
1000
- function mergeDeep(target, ...sources) {
1001
- if (!sources.length)
1002
- return target;
1003
- const source = sources.shift();
1004
- if (isObject(target) && isObject(source)) {
1005
- for (const key in source) {
1006
- if (isObject(source[key])) {
1007
- if (!target[key])
1008
- Object.assign(target, { [key]: {} });
1009
- mergeDeep(target[key], source[key]);
1010
- }
1011
- else {
1012
- Object.assign(target, { [key]: source[key] });
1013
- }
1014
- }
1015
- }
1016
- return mergeDeep(target, ...sources);
1028
+ function getNextMonth(date) {
1029
+ const nextMonth = new Date(date);
1030
+ nextMonth.setMonth(date.getMonth() + 1);
1031
+ return nextMonth;
1017
1032
  }
1018
1033
  /**
1019
- * Get type's property name safety
1020
- * @param name KeyOf property
1021
- * @returns Type's property name
1034
+ * Get previous month as date
1035
+ * @param date Date value
1036
+ * @returns Previous month as date
1022
1037
  */
1023
- const nameof = (name) => name;
1024
- /**
1025
- * Determines if the input is a Number or something that can be coerced to a Number
1026
- * @param number The input to be tested
1027
- * @returns - An indication if the input is a Number or can be coerced to a Number
1028
- */
1029
- function isNumeric(number) {
1030
- return !isNaN(parseFloat(number));
1038
+ function getPreviousMonth(date) {
1039
+ const prevMonth = new Date(date);
1040
+ prevMonth.setMonth(date.getMonth() - 1);
1041
+ return prevMonth;
1031
1042
  }
1032
1043
  /**
1033
- * Determines if the input is a string
1034
- * @param value The input to be tested
1035
- * @returns An indication if the input is a string
1044
+ * Get next year as date
1045
+ * @param date Date value
1046
+ * @returns Next year as date
1036
1047
  */
1037
- function isString(value) {
1038
- return typeof value === 'string';
1048
+ function getNextYear(date) {
1049
+ const nextYear = new Date(date);
1050
+ nextYear.setFullYear(date.getFullYear() + 1);
1051
+ return nextYear;
1039
1052
  }
1040
1053
  /**
1041
- * Return true if current browser is Chrome
1042
- * @returns If current browser is Chrome
1054
+ * Get previous year as date
1055
+ * @param date Date value
1056
+ * @returns Previous year as date
1043
1057
  */
1044
- function isChromeBrowser() {
1045
- return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
1058
+ function getPreviousYear(date) {
1059
+ const prevYear = new Date(date);
1060
+ prevYear.setFullYear(date.getFullYear() - 1);
1061
+ return prevYear;
1046
1062
  }
1047
1063
  /**
1048
- * Return true if value is valid email address
1049
- * @returns True if it's valid email address
1064
+ * Return first day of month as date from date value
1065
+ * @param date Date value
1066
+ * @returns First day of month as date
1050
1067
  */
1051
- function isEmail(value) {
1052
- return isDefined(value.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/));
1068
+ function getFirstDayOfMonth(date) {
1069
+ if (isDefined(date) && date instanceof Date) {
1070
+ const year = date.getFullYear(), month = date.getMonth();
1071
+ return new Date(year, month, 1);
1072
+ }
1073
+ return date;
1053
1074
  }
1054
1075
  /**
1055
- * Return true if string is "true"
1056
- * @returns parsed string as boolean
1076
+ * Return last day of month as date from date value
1077
+ * @param date Date value
1078
+ * @returns Last day of month as date
1057
1079
  */
1058
- function parseBoolean(value) {
1059
- return /^true$/i.test(value);
1080
+ function getLastDayOfMonth(date) {
1081
+ if (isDefined(date) && date instanceof Date) {
1082
+ const year = date.getFullYear(), month = date.getMonth();
1083
+ return new Date(year, month + 1, 0);
1084
+ }
1085
+ return date;
1060
1086
  }
1061
1087
  /**
1062
- * Return true if values equal
1063
- * @param obj1 First value to compare
1064
- * @param obj2 Second value to compare
1065
- * @returns True if equal
1088
+ * Return first day of year as date from date value
1089
+ * @param date Date value
1090
+ * @returns First day of year as date
1066
1091
  */
1067
- function isEqual(obj1, obj2) {
1068
- /**
1069
- * More accurately check the type of a JavaScript object
1070
- * @param {Object} obj The object
1071
- * @return {String} The object type
1072
- */
1073
- function getType(obj) {
1074
- return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
1075
- }
1076
- function areArraysEqual() {
1077
- // Check length
1078
- if (obj1.length !== obj2.length)
1079
- return false;
1080
- // Check each item in the array
1081
- for (let i = 0; i < obj1.length; i++) {
1082
- if (!isEqual(obj1[i], obj2[i]))
1083
- return false;
1084
- }
1085
- // If no errors, return true
1086
- return true;
1087
- }
1088
- function areObjectsEqual() {
1089
- if (Object.keys(obj1).length !== Object.keys(obj2).length)
1090
- return false;
1091
- // Check each item in the object
1092
- for (let key in obj1) {
1093
- if (Object.prototype.hasOwnProperty.call(obj1, key)) {
1094
- if (!isEqual(obj1[key], obj2[key])) {
1095
- return false;
1096
- }
1097
- }
1098
- }
1099
- // If no errors, return true
1100
- return true;
1101
- }
1102
- function areFilesEqual() {
1103
- return obj1.lastModified === obj2.lastModified
1104
- && obj1.size === obj2.size
1105
- && obj1.type === obj2.type;
1106
- }
1107
- function areFunctionsEqual() {
1108
- return obj1.toString() === obj2.toString();
1109
- }
1110
- function arePrimativesEqual() {
1111
- return obj1 === obj2;
1092
+ function getFirstDayOfYear(date) {
1093
+ if (isDefined(date) && date instanceof Date) {
1094
+ return new Date(date.getFullYear(), 0, 1);
1112
1095
  }
1113
- function areDatesEqual() {
1114
- return isEqualDateTimes(obj1, obj2);
1096
+ return date;
1097
+ }
1098
+ /**
1099
+ * Return last day of year as date from date value
1100
+ * @param date Date value
1101
+ * @returns Last day of year as date
1102
+ */
1103
+ function getLastDayOfYear(date) {
1104
+ if (isDefined(date) && date instanceof Date) {
1105
+ return new Date(date.getFullYear(), 12, 0);
1115
1106
  }
1116
- // Get the object type
1117
- let type = getType(obj1);
1118
- // If the two items are not the same type, return false
1119
- if (type !== getType(obj2))
1120
- return false;
1121
- // Compare based on type
1122
- if (type === 'array')
1123
- return areArraysEqual();
1124
- if (type === 'date')
1125
- return areDatesEqual();
1126
- if (type === 'file')
1127
- return areFilesEqual();
1128
- if (type === 'object')
1129
- return areObjectsEqual();
1130
- if (type === 'function')
1131
- return areFunctionsEqual();
1132
- return arePrimativesEqual();
1107
+ return date;
1133
1108
  }
1134
1109
  /**
1135
- * Generate unique identificator
1136
- * @returns Random GUID
1110
+ * Return first day of month as date
1111
+ * @param year Year value
1112
+ * @param month Month value
1113
+ * @returns First day of month
1137
1114
  */
1138
- function generateGuid() {
1139
- let S4 = function () {
1140
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1141
- };
1142
- return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
1115
+ function getFirstDayOfMonthByYearAndMonth(year, month) {
1116
+ return new Date(year, month, 1);
1143
1117
  }
1144
1118
  /**
1145
- * Check if value is Json parsable string
1146
- * @param value string value
1147
- * @returns True if string can be JSON parsed
1119
+ * Return last day of month as date
1120
+ * @param year Year value
1121
+ * @param month Month value
1122
+ * @returns Last day of month
1148
1123
  */
1149
- function isJsonString(value) {
1150
- try {
1151
- const json = JSON.parse(value);
1152
- return (typeof json === 'object');
1153
- }
1154
- catch (e) {
1155
- return false;
1156
- }
1124
+ function getLastDayOfMonthByYearAndMonth(year, month) {
1125
+ return new Date(year, month + 1, 0);
1126
+ }
1127
+ /**
1128
+ * Return week number in month from date value
1129
+ * @param date Date value
1130
+ * @returns Week number
1131
+ */
1132
+ function getWeeksNumberInMonth(date) {
1133
+ const firstOfMonth = getFirstDayOfMonth(date), lastOfMonth = getLastDayOfMonth(date), used = firstOfMonth.getDay() + lastOfMonth.getDate();
1134
+ return Math.ceil(used / DateTimeConstants.DAYS_IN_WEEK);
1135
+ }
1136
+ /**
1137
+ * Return true if first and second date are equal
1138
+ * @param date1 First date value
1139
+ * @param date2 Second date value
1140
+ * @returns True if first and second date are equal
1141
+ */
1142
+ function isEqualDates(date1, date2) {
1143
+ const date1Value = new Date(date1), date2Value = new Date(date2);
1144
+ date1Value.setHours(0, 0, 0, 0);
1145
+ date2Value.setHours(0, 0, 0, 0);
1146
+ return date1Value.getTime() === date2Value.getTime();
1147
+ }
1148
+ /**
1149
+ * Return true if first and second datetime are equal
1150
+ * @param date1 First datetime value
1151
+ * @param date2 Second datetime value
1152
+ * @returns True if first and second datetime are equal
1153
+ */
1154
+ function isEqualDateTimes(date1, date2) {
1155
+ const date1Value = new Date(date1), date2Value = new Date(date2);
1156
+ return date1Value.getTime() === date2Value.getTime();
1157
+ }
1158
+ /**
1159
+ * Return true if first date greater than second date
1160
+ * @param date1 First date value
1161
+ * @param date2 Second date value
1162
+ * @returns True if first date greater than second date
1163
+ */
1164
+ function isDateGreat(date1, date2) {
1165
+ return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
1166
+ > new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
1157
1167
  }
1158
1168
  /**
1159
- * Stop propagation and prevent default
1160
- * @param event Event object
1169
+ * Return true if first date greater or equal to second date
1170
+ * @param date1 First date value
1171
+ * @param date2 Second date value
1172
+ * @returns True if first date greater or equal to second date
1161
1173
  */
1162
- function stopAndPreventPropagation(event) {
1163
- event.preventDefault();
1164
- event.stopPropagation();
1165
- }
1166
-
1174
+ function isDateGreatOrEqual(date1, date2) {
1175
+ return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate())
1176
+ >= new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
1177
+ }
1167
1178
  /**
1168
- * Return true if string has value(not empty string)
1169
- * @param value String value to check
1170
- * @returns True if string is not null and defined(not empty string)
1179
+ * Return true if first date time greater than second date time
1180
+ * @param date1 First date time value
1181
+ * @param date2 Second date time value
1182
+ * @returns True if first date time greater than second date time
1171
1183
  */
1172
- function isNullOrEmptyString(value) {
1173
- return !isDefined(value) || value === CommonConstants.EMPTY_STRING;
1184
+ function isDateTimeGreat(date1, date2) {
1185
+ return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(), date1.getHours(), date1.getMinutes())
1186
+ > new Date(date2.getFullYear(), date2.getMonth(), date2.getDate(), date2.getHours(), date2.getMinutes());
1174
1187
  }
1175
1188
  /**
1176
- * Return true if value contains includeValue
1177
- * @param value String value to check
1178
- * @param includeValue Value to check if it include
1179
- * @returns True if value contains includeValue
1189
+ * Return true if first date time greater or equal to second date time
1190
+ * @param date1 First date time value
1191
+ * @param date2 Second date time value
1192
+ * @returns True if first date time greater or equal to second date time
1180
1193
  */
1181
- function contains(value, includeValue) {
1182
- return !isNullOrEmptyString(value) && !isNullOrEmptyString(includeValue)
1183
- ? value.toLowerCase()
1184
- .includes(includeValue.toLowerCase())
1185
- : false;
1194
+ function isDateTimeGreatOrEqual(date1, date2) {
1195
+ return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(), date1.getHours(), date1.getMinutes())
1196
+ >= new Date(date2.getFullYear(), date2.getMonth(), date2.getDate(), date2.getHours(), date2.getMinutes());
1186
1197
  }
1187
1198
  /**
1188
- * Return trimed value
1189
- * @param value Value for trim modification
1190
- * @returns Trimed value
1199
+ * Return true if first time greater or equal to second time
1200
+ * @param date1 First date time value
1201
+ * @param date2 Second date time value
1202
+ * @returns True if first time greater or equal to second time
1191
1203
  */
1192
- function trim(value) {
1193
- return isNullOrEmptyString(value) ? value : value.replace(/\s/g, '');
1194
- }
1195
-
1204
+ function isTimeGreatOrEqual(date1, date2) {
1205
+ return new Date(0, 0, 0, date1.getHours(), date1.getMinutes())
1206
+ >= new Date(0, 0, 0, date2.getHours(), date2.getMinutes());
1207
+ }
1196
1208
  /**
1197
- * Return parsed file size as string
1198
- * @param bytes Bytes count
1199
- * @param decimals Value after dot
1200
- * @returns Parsed file size
1209
+ * Return true if first time less or equal to second time
1210
+ * @param date1 First date time value
1211
+ * @param date2 Second date time value
1212
+ * @returns True if first time less or equal to second time
1201
1213
  */
1202
- function parseFileSize(bytes, decimals = 2) {
1203
- if (bytes === 0)
1204
- return '0';
1205
- const k = 1024;
1206
- const dm = decimals < 0 ? 0 : decimals;
1207
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
1208
- const i = Math.floor(Math.log(bytes) / Math.log(k));
1209
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
1214
+ function isDateTimeLessOrEqual(date1, date2) {
1215
+ return new Date(0, 0, 0, date1.getHours(), date1.getMinutes())
1216
+ <= new Date(0, 0, 0, date2.getHours(), date2.getMinutes());
1210
1217
  }
1211
1218
  /**
1212
- * Return file extension
1213
- * @param file File value
1214
- * @returns File extension
1219
+ * Return true if first time less or equal to second time
1220
+ * @param date1 First date time value
1221
+ * @param date2 Second date time value
1222
+ * @returns True if first time less or equal to second time
1215
1223
  */
1216
- function getFileExtension(file) {
1217
- if (!isDefined(file))
1218
- return CommonConstants.EMPTY_STRING;
1219
- if (file.name.indexOf('.') === CommonConstants.NOT_FOUND_INDEX) {
1220
- return CommonConstants.EMPTY_STRING;
1221
- }
1222
- return file.name.split('.').pop();
1224
+ function isTimeLessOrEqual(date1, date2) {
1225
+ return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(), date1.getHours(), date1.getMinutes())
1226
+ <= new Date(date2.getFullYear(), date2.getMonth(), date2.getDate(), date2.getHours(), date2.getMinutes());
1223
1227
  }
1224
1228
  /**
1225
- * Read file as data URL
1226
- * @param file File value
1227
- * @param onLoad On load action
1229
+ * Convert UTC date to local
1230
+ * @param date Date value
1231
+ * @returns Locale date
1228
1232
  */
1229
- function readAsDataURL(file, onLoad) {
1230
- if (isDefined(file)) {
1231
- const reader = new FileReader();
1232
- reader.onload = () => onLoad(reader.result);
1233
- reader.readAsDataURL(file);
1234
- }
1235
- else
1236
- throw new Error('File utils | Read as data URL function --> File is empty.');
1233
+ function convertUTCDateToLocalDate(date) {
1234
+ return new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
1237
1235
  }
1238
1236
  /**
1239
- * Return true if file is image
1240
- * @param file File value
1241
- * @returns True if file is image
1237
+ * Convert Json representation of timestamp to date value
1238
+ * @param timestamp Timestamp for example - 12:23:45
1239
+ * @returns Date value
1242
1240
  */
1243
- function isImage(file) {
1244
- return isDefined(file) && (/\.(gif|jpe?g|jpg|tiff|png|webp|bmp)$/i).test(file.name);
1241
+ function convertTimestampToDate(timestamp) {
1242
+ const tempTime = timestamp.split(":"), result = new Date();
1243
+ result.setHours(+tempTime[0]);
1244
+ result.setMinutes(+tempTime[1]);
1245
+ result.setSeconds(+tempTime[2]);
1246
+ return result;
1245
1247
  }
1246
1248
  /**
1247
- * Convert file to base64 string
1248
- * @param file File value
1249
- * @returns Base64 string
1249
+ * Convert Date object to timestamp string
1250
+ * @param date Date value
1251
+ * @param locale Locale value
1252
+ * @returns String representation of date value, for example - 12:23
1250
1253
  */
1251
- function convertToBase64String(file) {
1252
- return new Promise((resolve, reject) => {
1253
- const reader = new FileReader();
1254
- reader.readAsDataURL(file);
1255
- reader.onload = () => resolve(reader.result);
1256
- reader.onerror = reject;
1257
- });
1254
+ function convertDateToTimestamp(date, locale = DateTimeConstants.DEFAULT_LOCALE) {
1255
+ return `${formatDate(date, 'HH', locale)}:${formatDate(date, 'mm', locale)}`;
1258
1256
  }
1259
1257
  /**
1260
- * Convert base64 string to file
1261
- * @param base64 Base64 string
1262
- * @param name File name
1263
- * @returns File value
1258
+ * Get age from
1259
+ * @param birthdate Date of birth
1260
+ * @returns Age
1264
1261
  */
1265
- async function convertFromBase64String(base64, name) {
1266
- const res = await fetch(base64), blob = await res.blob(), extension = base64.substring("data:image/".length, base64.indexOf(";base64"));
1267
- return new File([blob], `${name}.${extension}`, { type: `image/${extension}` });
1262
+ function getAge(birthdate) {
1263
+ if (!birthdate)
1264
+ return null;
1265
+ const now = new Date();
1266
+ let age = now.getFullYear() - birthdate.getFullYear();
1267
+ const monthDifference = now.getMonth() - birthdate.getMonth();
1268
+ if (monthDifference < 0 || (monthDifference === 0 && now.getDate() < birthdate.getDate())) {
1269
+ age--;
1270
+ }
1271
+ return age;
1268
1272
  }
1269
1273
 
1270
1274
  /**
1271
- * Return CSS like value
1272
- * @param value Value as number
1273
- * @returns Value as '1px'
1274
- */
1275
- function getCssLikeValue(value, type = UIConstants.CSS_PIXELS) {
1276
- return value + type;
1277
- }
1278
- /**
1279
- * Parse CSS like value to number
1280
- * @param value CSS like value
1281
- * @returns Number value
1275
+ * Return true if value defined
1276
+ * @param value Value to check
1277
+ * @returns True if value is not null and defined
1282
1278
  */
1283
- function getValueFromCssLikeValue(value, type = UIConstants.CSS_PIXELS) {
1284
- return +value.replace(type, CommonConstants.EMPTY_STRING);
1279
+ function isDefined(value) {
1280
+ return value !== undefined && value !== null;
1285
1281
  }
1286
1282
  /**
1287
- * Return CCS like calc value
1288
- * @param value All value (100% by default)
1289
- * @param part Part value
1290
- * @returns Calc value
1283
+ * Return true if value is object
1284
+ * @param value Value to check
1285
+ * @returns True if value is object
1291
1286
  */
1292
- function getCalcValue(part, value = 100) {
1293
- return `calc(${value}${UIConstants.CSS_PERCENTAGE} / ${part} )`;
1287
+ function isObject(value) {
1288
+ return (isDefined(value) && typeof value === 'object'
1289
+ && !Array.isArray(value)
1290
+ && !(value instanceof Date || value instanceof File));
1294
1291
  }
1295
1292
  /**
1296
- * Return CCS like rotate value
1297
- * @param value value as degrees
1298
- * @returns Rotate value
1293
+ * Return true if data is observable
1294
+ * @param data Object to check
1295
+ * @returns True if data is observable
1299
1296
  */
1300
- function getRotateValue(value) {
1301
- return `rotate(${value}deg)`;
1297
+ function isAsyncData(data) {
1298
+ return data instanceof Observable;
1302
1299
  }
1303
1300
  /**
1304
- * Add classes to HTML element
1305
- * @param element HTML element
1306
- * @param classNames Array of CSS classes
1301
+ * Return extended object with new property
1302
+ * @param obj Object to extend by property
1303
+ * @param property New property name
1304
+ * @param value Value for new property
1305
+ * @returns Extended object with new property
1307
1306
  */
1308
- function addClasses(element, ...classNames) {
1309
- if (isDefined(element)) {
1310
- classNames.forEach((className) => element.classList.add(className));
1307
+ function addPropertyToObject(obj, property, value = null) {
1308
+ if (isDefined(property) && !obj.hasOwnProperty(property)) {
1309
+ let newObj = {};
1310
+ newObj[property] = value;
1311
+ obj = { ...obj, ...newObj };
1311
1312
  }
1313
+ return obj;
1312
1314
  }
1313
1315
  /**
1314
- * Remove classes to HTML element
1315
- * @param element HTML element
1316
- * @param classNames Array of CSS classes
1316
+ * Remove property from object
1317
+ * @param obj Object for removing property
1318
+ * @param property Property name to remove
1317
1319
  */
1318
- function removeClasses(element, ...classNames) {
1319
- if (isDefined(element)) {
1320
- classNames.forEach((className) => element.classList.remove(className));
1320
+ function removePropertyFromObject(obj, property) {
1321
+ if (obj.hasOwnProperty(property)) {
1322
+ delete obj[property];
1321
1323
  }
1322
1324
  }
1323
1325
  /**
1324
- * Convert RGB color to HEX
1325
- * @param r Red
1326
- * @param g Green
1327
- * @param b Blue
1328
- * @returns HEX value
1329
- */
1330
- function rgbToHex(r, g, b) {
1331
- return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
1332
- }
1333
- /**
1334
- * Convert HEX to RGB value
1335
- * @param hex HEX value
1336
- * @returns RGB value
1326
+ * Deep merge object with others
1327
+ * @param target Object to merge
1328
+ * @param sources Objects to be merged with target
1329
+ * @returns Merged object
1337
1330
  */
1338
- function hexToRgb(hex) {
1339
- var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1340
- if (result) {
1341
- var r = parseInt(result[1], 16);
1342
- var g = parseInt(result[2], 16);
1343
- var b = parseInt(result[3], 16);
1344
- return `rgb(${r}, ${g}, ${b})`;
1331
+ function mergeDeep(target, ...sources) {
1332
+ if (!sources.length)
1333
+ return target;
1334
+ const source = sources.shift();
1335
+ if (isObject(target) && isObject(source)) {
1336
+ for (const key in source) {
1337
+ if (isObject(source[key])) {
1338
+ if (!target[key])
1339
+ Object.assign(target, { [key]: {} });
1340
+ mergeDeep(target[key], source[key]);
1341
+ }
1342
+ else {
1343
+ Object.assign(target, { [key]: source[key] });
1344
+ }
1345
+ }
1345
1346
  }
1346
- return null;
1347
+ return mergeDeep(target, ...sources);
1347
1348
  }
1348
1349
  /**
1349
- * Set opacity for RGB value
1350
- * @param rgb Rgb value with {opacity} placeholder
1351
- * @param opacity Opacity value
1352
- * @returns RGB value with relevant opacity
1350
+ * Get type's property name safety
1351
+ * @param name KeyOf property
1352
+ * @returns Type's property name
1353
1353
  */
1354
- function replaceRgbOpacity(rgb, opacity) {
1355
- return rgb.replace(UIConstants.RGB_OPACITY_PLACEHOLDER, opacity.toString());
1356
- }
1357
-
1354
+ const nameof = (name) => name;
1358
1355
  /**
1359
- * Return true if collection not empty
1360
- * @param collection Array of items
1361
- * @returns True if collection not empty
1362
- */
1363
- function any(collection) {
1364
- return isDefined(collection) && collection.length > 0;
1356
+ * Determines if the input is a Number or something that can be coerced to a Number
1357
+ * @param number The input to be tested
1358
+ * @returns - An indication if the input is a Number or can be coerced to a Number
1359
+ */
1360
+ function isNumeric(number) {
1361
+ return !isNaN(parseFloat(number));
1365
1362
  }
1366
1363
  /**
1367
- * Return true if collection has such value
1368
- * @param collection Array of items
1369
- * @param value Value to check
1370
- * @returns True if found value in collection
1364
+ * Determines if the input is a string
1365
+ * @param value The input to be tested
1366
+ * @returns An indication if the input is a string
1371
1367
  */
1372
- function hasItem(collection, value) {
1373
- return any(collection)
1374
- && collection.findIndex(item => item === value) !== CommonConstants.NOT_FOUND_INDEX;
1368
+ function isString(value) {
1369
+ return typeof value === 'string';
1375
1370
  }
1376
1371
  /**
1377
- * Return true if collection has such value by predicate function
1378
- * @param collection Array of items
1379
- * @param predicate Function to define check logic
1380
- * @returns True if found value in collection
1372
+ * Return true if current browser is Chrome
1373
+ * @returns If current browser is Chrome
1381
1374
  */
1382
- function hasItemBy(collection, predicate) {
1383
- return any(collection) && collection.findIndex(predicate) !== CommonConstants.NOT_FOUND_INDEX;
1375
+ function isChromeBrowser() {
1376
+ return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
1384
1377
  }
1385
1378
  /**
1386
- * Return true if collection of objects has such value as object
1387
- * @param collection Array of objects
1388
- * @param property Property name
1389
- * @param value Value to check
1390
- * @returns True if found value in collection
1379
+ * Return true if value is valid email address
1380
+ * @returns True if it's valid email address
1391
1381
  */
1392
- function hasObjectItem(collection, // TODO <-- Array<T>
1393
- property, value) {
1394
- return any(collection)
1395
- && collection.findIndex(item => item.hasOwnProperty(property)
1396
- && item[property] === value) !== CommonConstants.NOT_FOUND_INDEX;
1382
+ function isEmail(value) {
1383
+ return isDefined(value.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/));
1397
1384
  }
1398
1385
  /**
1399
- * Return true if first collection has item in second collection
1400
- * @param collection1 Array of objects where search
1401
- * @param collection2 Array of objects where try to find
1402
- * @returns
1386
+ * Return true if string is "true"
1387
+ * @returns parsed string as boolean
1403
1388
  */
1404
- function hasAnyItem(collection1, collection2) {
1405
- return collection1.some(item => collection2.includes(item));
1389
+ function parseBoolean(value) {
1390
+ return /^true$/i.test(value);
1406
1391
  }
1407
1392
  /**
1408
- * Return value from collection by predicate function
1409
- * @param collection Array of items
1410
- * @param predicate Function to define search logic
1411
- * @returns Value from collection
1393
+ * Return true if values equal
1394
+ * @param obj1 First value to compare
1395
+ * @param obj2 Second value to compare
1396
+ * @returns True if equal
1412
1397
  */
1413
- function firstOrDefault(collection, predicate) {
1414
- return any(collection) ? collection?.find(predicate) : undefined;
1398
+ function isEqual(obj1, obj2) {
1399
+ /**
1400
+ * More accurately check the type of a JavaScript object
1401
+ * @param {Object} obj The object
1402
+ * @return {String} The object type
1403
+ */
1404
+ function getType(obj) {
1405
+ return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
1406
+ }
1407
+ function areArraysEqual() {
1408
+ // Check length
1409
+ if (obj1.length !== obj2.length)
1410
+ return false;
1411
+ // Check each item in the array
1412
+ for (let i = 0; i < obj1.length; i++) {
1413
+ if (!isEqual(obj1[i], obj2[i]))
1414
+ return false;
1415
+ }
1416
+ // If no errors, return true
1417
+ return true;
1418
+ }
1419
+ function areObjectsEqual() {
1420
+ if (Object.keys(obj1).length !== Object.keys(obj2).length)
1421
+ return false;
1422
+ // Check each item in the object
1423
+ for (let key in obj1) {
1424
+ if (Object.prototype.hasOwnProperty.call(obj1, key)) {
1425
+ if (!isEqual(obj1[key], obj2[key])) {
1426
+ return false;
1427
+ }
1428
+ }
1429
+ }
1430
+ // If no errors, return true
1431
+ return true;
1432
+ }
1433
+ function areFilesEqual() {
1434
+ return obj1.lastModified === obj2.lastModified
1435
+ && obj1.size === obj2.size
1436
+ && obj1.type === obj2.type;
1437
+ }
1438
+ function areFunctionsEqual() {
1439
+ return obj1.toString() === obj2.toString();
1440
+ }
1441
+ function arePrimativesEqual() {
1442
+ return obj1 === obj2;
1443
+ }
1444
+ function areDatesEqual() {
1445
+ return isEqualDateTimes(obj1, obj2);
1446
+ }
1447
+ // Get the object type
1448
+ let type = getType(obj1);
1449
+ // If the two items are not the same type, return false
1450
+ if (type !== getType(obj2))
1451
+ return false;
1452
+ // Compare based on type
1453
+ if (type === 'array')
1454
+ return areArraysEqual();
1455
+ if (type === 'date')
1456
+ return areDatesEqual();
1457
+ if (type === 'file')
1458
+ return areFilesEqual();
1459
+ if (type === 'object')
1460
+ return areObjectsEqual();
1461
+ if (type === 'function')
1462
+ return areFunctionsEqual();
1463
+ return arePrimativesEqual();
1415
1464
  }
1416
1465
  /**
1417
- * Return first item from collection
1418
- * @param collection Array of items
1419
- * @returns First value from collection
1466
+ * Generate unique identificator
1467
+ * @returns Random GUID
1420
1468
  */
1421
- function firstItem(collection) {
1422
- return any(collection) ? collection[0] : null;
1469
+ function generateGuid() {
1470
+ let S4 = function () {
1471
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1472
+ };
1473
+ return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
1423
1474
  }
1424
1475
  /**
1425
- * Return last item from collection
1426
- * @param collection Array of items
1427
- * @returns Last value from collection
1476
+ * Check if value is Json parsable string
1477
+ * @param value string value
1478
+ * @returns True if string can be JSON parsed
1428
1479
  */
1429
- function lastItem(collection) {
1430
- return any(collection) ? collection[collection.length - 1] : null;
1480
+ function isJsonString(value) {
1481
+ try {
1482
+ const json = JSON.parse(value);
1483
+ return (typeof json === 'object');
1484
+ }
1485
+ catch (e) {
1486
+ return false;
1487
+ }
1431
1488
  }
1432
1489
  /**
1433
- * Return True if all values match predicate function
1434
- * @param collection Array of objects
1435
- * @param predicate Function to define check logic
1436
- * @returns True if all values match predicate
1490
+ * Stop propagation and prevent default
1491
+ * @param event Event object
1437
1492
  */
1438
- function all(collection, predicate) {
1439
- return any(collection) ? collection.filter(predicate).length == collection.length : false;
1493
+ function stopAndPreventPropagation(event) {
1494
+ event.preventDefault();
1495
+ event.stopPropagation();
1440
1496
  }
1441
1497
  /**
1442
- * Return count by predicate
1443
- * @param collection Array of objects
1444
- * @param predicate Function to define check logic
1445
- * @returns Items count
1498
+ * Update property in object by key
1499
+ * @param obj Object to change
1500
+ * @param propertyKey Property to change
1501
+ * @param newPropertyValue New property value
1502
+ * @param oldPropertyValue Old property value
1503
+ * @returns Updated object
1446
1504
  */
1447
- function count(collection, predicate) {
1448
- return collection.filter(predicate).length;
1505
+ function updatePropertyByKey(obj, propertyKey, newPropertyValue, oldPropertyValue) {
1506
+ if (Array.isArray(obj)) {
1507
+ return obj.map(item => {
1508
+ return isObject(item) && item !== null
1509
+ ? updatePropertyByKey(item, propertyKey, newPropertyValue, oldPropertyValue)
1510
+ : item;
1511
+ });
1512
+ }
1513
+ else if (isObject(obj) && obj !== null) {
1514
+ const updatedObj = {};
1515
+ for (const key in obj) {
1516
+ if (key === propertyKey) {
1517
+ if (Array.isArray(obj[key])) {
1518
+ if (hasItem(obj[key], oldPropertyValue)) {
1519
+ removeItem(obj[key], oldPropertyValue);
1520
+ }
1521
+ else {
1522
+ addItem(obj[key], oldPropertyValue);
1523
+ }
1524
+ updatedObj[key] = obj[key];
1525
+ }
1526
+ else {
1527
+ updatedObj[key] = newPropertyValue;
1528
+ }
1529
+ }
1530
+ else {
1531
+ updatedObj[key] = updatePropertyByKey(obj[key], propertyKey, newPropertyValue, oldPropertyValue);
1532
+ }
1533
+ }
1534
+ return updatedObj;
1535
+ }
1536
+ return obj;
1449
1537
  }
1450
1538
  /**
1451
- * Return items from collection by predicate function
1452
- * @param collection Array of items
1453
- * @param predicate Function to define search logic
1454
- * @returns Values from collection
1539
+ * Get changed property path
1540
+ * @param previous Previous value
1541
+ * @param current Currency value
1542
+ * @param parentKey Parent object key name
1543
+ * @returns Path of property that was changed
1455
1544
  */
1456
- function where(collection, predicate) {
1457
- return any(collection) ? collection.filter(predicate) : null;
1545
+ function findChangedPropertyPath(previous, current, parentKey = '') {
1546
+ for (const key of Object.keys(current)) {
1547
+ const fullKey = parentKey ? `${parentKey}.${key}` : key;
1548
+ if (isObject(current[key]) && current[key] !== null && previous[key]) {
1549
+ const nestedChange = findChangedPropertyPath(previous[key], current[key], fullKey);
1550
+ if (nestedChange) {
1551
+ return nestedChange;
1552
+ }
1553
+ }
1554
+ else {
1555
+ if (previous[key] !== current[key]) {
1556
+ return fullKey;
1557
+ }
1558
+ }
1559
+ }
1560
+ return null;
1458
1561
  }
1459
1562
  /**
1460
- * Return sliced collection by page number and page size
1461
- * @param collection Array of items
1462
- * @param page Page number
1463
- * @param size Page size
1464
- * @returns Sliced collection
1563
+ * Get changed property key
1564
+ * @param previous Previous value
1565
+ * @param current Currency value
1566
+ * @returns Key of property that was changed
1465
1567
  */
1466
- function skip(collection, page, size) {
1467
- if (any(collection)) {
1468
- let start = (page - 1) * size;
1469
- return collection.slice(start, start + size);
1470
- }
1471
- return collection;
1568
+ function findChangedPropertyKey(previous, current) {
1569
+ const path = findChangedPropertyPath(previous, current), parts = path?.split('.');
1570
+ return parts && parts.length ? parts[parts.length - 1] : undefined;
1472
1571
  }
1473
- function sort(collection, direction = SortingDirection.Ascending) {
1474
- if (any(collection)) {
1475
- return direction == SortingDirection.Ascending
1476
- ? collection.sort((a, b) => a - b)
1477
- : collection.sort((a, b) => b - a);
1478
- }
1479
- return collection;
1572
+ function deepClone(value) {
1573
+ return JSON.parse(JSON.stringify(value));
1574
+ }
1575
+
1576
+ /**
1577
+ * Return parsed file size as string
1578
+ * @param bytes Bytes count
1579
+ * @param decimals Value after dot
1580
+ * @returns Parsed file size
1581
+ */
1582
+ function parseFileSize(bytes, decimals = 2) {
1583
+ if (bytes === 0)
1584
+ return '0';
1585
+ const k = 1024;
1586
+ const dm = decimals < 0 ? 0 : decimals;
1587
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
1588
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
1589
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
1480
1590
  }
1481
1591
  /**
1482
- * Return sorted collection of objects by property
1483
- * @param collection Array of items
1484
- * @param property Property name
1485
- * @param direction Sorting direction
1486
- * @returns Sorted collection
1592
+ * Return file extension
1593
+ * @param file File value
1594
+ * @returns File extension
1487
1595
  */
1488
- function sortBy(collection, property, direction) {
1489
- if (any(collection)) {
1490
- let _sortFunc = (a, b) => (t1, t2) => (a[property] > b[property] ? t1 : t2);
1491
- return direction == SortingDirection.Ascending
1492
- ? collection.sort((a, b) => _sortFunc(a, b)(1, -1))
1493
- : collection.sort((a, b) => _sortFunc(a, b)(-1, 1));
1596
+ function getFileExtension(file) {
1597
+ if (!isDefined(file))
1598
+ return CommonConstants.EMPTY_STRING;
1599
+ if (file.name.indexOf('.') === CommonConstants.NOT_FOUND_INDEX) {
1600
+ return CommonConstants.EMPTY_STRING;
1494
1601
  }
1495
- return collection;
1602
+ return file.name.split('.').pop();
1496
1603
  }
1497
1604
  /**
1498
- * Return sorted collection of objects by path
1499
- * @param collection Array of items
1500
- * @param path Path to property
1501
- * @param direction Sorting direction
1502
- * @returns Sorted collection
1605
+ * Read file as data URL
1606
+ * @param file File value
1607
+ * @param onLoad On load action
1503
1608
  */
1504
- function sortByPath(collection, path, direction) {
1505
- if (any(collection)) {
1506
- if (isNullOrEmptyString(path))
1507
- throw new Error('Collection utils | Sort By Path function --> Path is empty.');
1508
- const pathParts = path.split('.');
1509
- if (!any(pathParts))
1510
- throw new Error('Collection utils | Sort By Path function --> Path is incorrect.');
1511
- const partsLength = pathParts.length;
1512
- collection.sort((a, b) => {
1513
- var i = 0;
1514
- while (i < partsLength) {
1515
- a = a[pathParts[i]];
1516
- b = b[pathParts[i]];
1517
- i++;
1518
- }
1519
- return direction == SortingDirection.Ascending
1520
- ? a >= b ? 1 : -1
1521
- : a > b ? -1 : 1;
1522
- });
1523
- return collection;
1609
+ function readAsDataURL(file, onLoad) {
1610
+ if (isDefined(file)) {
1611
+ const reader = new FileReader();
1612
+ reader.onload = () => onLoad(reader.result);
1613
+ reader.readAsDataURL(file);
1524
1614
  }
1525
- return collection;
1615
+ else
1616
+ throw new Error('File utils | Read as data URL function --> File is empty.');
1526
1617
  }
1527
1618
  /**
1528
- * Return collection without matches
1529
- * @param collection Array of items
1530
- * @returns Collection without matches
1619
+ * Return true if file is image
1620
+ * @param file File value
1621
+ * @returns True if file is image
1531
1622
  */
1532
- function distinct(collection) {
1533
- return any(collection)
1534
- ? collection.filter((value, index, self) => self.indexOf(value) === index)
1535
- : collection;
1623
+ function isImage(file) {
1624
+ return isDefined(file) && (/\.(gif|jpe?g|jpg|tiff|png|webp|bmp)$/i).test(file.name);
1536
1625
  }
1537
1626
  /**
1538
- * Return sum value from collection items by map function
1539
- * @param collection Array of items
1540
- * @param select Map function
1541
- * @returns Sum value of colection items
1627
+ * Convert file to base64 string
1628
+ * @param file File value
1629
+ * @returns Base64 string
1542
1630
  */
1543
- function sum(collection, select) {
1544
- return any(collection)
1545
- ? collection
1546
- .map(select)
1547
- .reduce((a, b) => { return a + b; }, 0)
1548
- : 0;
1631
+ function convertToBase64String(file) {
1632
+ return new Promise((resolve, reject) => {
1633
+ const reader = new FileReader();
1634
+ reader.readAsDataURL(file);
1635
+ reader.onload = () => resolve(reader.result);
1636
+ reader.onerror = reject;
1637
+ });
1549
1638
  }
1550
1639
  /**
1551
- * Return max value from collection items by map function
1552
- * @param collection Array of items
1553
- * @param select Map function
1554
- * @returns Max value of collection items
1640
+ * Convert base64 string to file
1641
+ * @param base64 Base64 string
1642
+ * @param name File name
1643
+ * @returns File value
1555
1644
  */
1556
- function max(collection, select) {
1557
- if (any(collection))
1558
- return Math.max(...collection.map(select));
1559
- throw new Error('Collection utils | Max function --> Collection is empty.');
1645
+ async function convertFromBase64String(base64, name) {
1646
+ const res = await fetch(base64), blob = await res.blob(), extension = base64.substring("data:image/".length, base64.indexOf(";base64"));
1647
+ return new File([blob], `${name}.${extension}`, { type: `image/${extension}` });
1648
+ }
1649
+
1650
+ /**
1651
+ * Return CSS like value
1652
+ * @param value Value as number
1653
+ * @returns Value as '1px'
1654
+ */
1655
+ function getCssLikeValue(value, type = UIConstants.CSS_PIXELS) {
1656
+ return value + type;
1560
1657
  }
1561
1658
  /**
1562
- * Delete items from collection by predicate
1563
- * @param collection Array of items
1564
- * @param predicate Function to define remove logic
1659
+ * Parse CSS like value to number
1660
+ * @param value CSS like value
1661
+ * @returns Number value
1565
1662
  */
1566
- function remove(collection, predicate) {
1567
- var i = collection.length;
1568
- while (i--) {
1569
- if (predicate(collection[i])) {
1570
- collection.splice(i, 1);
1571
- }
1572
- }
1663
+ function getValueFromCssLikeValue(value, type = UIConstants.CSS_PIXELS) {
1664
+ return +value.replace(type, CommonConstants.EMPTY_STRING);
1573
1665
  }
1574
1666
  /**
1575
- * Add item to collection
1576
- * @param collection Array of items
1577
- * @param item New item
1578
- * @param predicate Function to define if allowed to add new item
1579
- * @returns True if successfully added
1667
+ * Return CCS like calc value
1668
+ * @param value All value (100% by default)
1669
+ * @param part Part value
1670
+ * @returns Calc value
1580
1671
  */
1581
- function addItem(collection, item, predicate = null) {
1582
- if (!isDefined(collection))
1583
- collection = new Array();
1584
- if (isDefined(predicate) && predicate(item))
1585
- return false;
1586
- collection.push(item);
1587
- return true;
1672
+ function getCalcValue(part, value = 100) {
1673
+ return `calc(${value}${UIConstants.CSS_PERCENTAGE} / ${part} )`;
1588
1674
  }
1589
1675
  /**
1590
- * Delete item from collection
1591
- * @param collection Array of items
1592
- * @param item Item to delete
1593
- * @returns True if successfully removed
1676
+ * Return CCS like rotate value
1677
+ * @param value value as degrees
1678
+ * @returns Rotate value
1594
1679
  */
1595
- function removeItem(collection, item) {
1596
- if (isDefined(item) && hasItem(collection, item)) {
1597
- collection.splice(collection.indexOf(item), 1);
1598
- return true;
1599
- }
1600
- return false;
1680
+ function getRotateValue(value) {
1681
+ return `rotate(${value}deg)`;
1601
1682
  }
1602
1683
  /**
1603
- * Delete item from collection by predicate
1604
- * @param collection Array of items
1605
- * @param predicate Function to define remove logic
1606
- * @returns True if successfully removed
1684
+ * Add classes to HTML element
1685
+ * @param element HTML element
1686
+ * @param classNames Array of CSS classes
1607
1687
  */
1608
- function removeItemBy(collection, predicate) {
1609
- const foundItem = firstOrDefault(collection, predicate);
1610
- if (isDefined(foundItem)) {
1611
- collection.splice(collection.indexOf(foundItem), 1);
1612
- return true;
1688
+ function addClasses(element, ...classNames) {
1689
+ if (isDefined(element)) {
1690
+ classNames.forEach((className) => element.classList.add(className));
1613
1691
  }
1614
- return false;
1615
1692
  }
1616
1693
  /**
1617
- * Update item in collection by predicate
1618
- * @param collection Array of items
1619
- * @param predicate Function to define item for deleting
1620
- * @returns True if successfully removed
1694
+ * Remove classes to HTML element
1695
+ * @param element HTML element
1696
+ * @param classNames Array of CSS classes
1621
1697
  */
1622
- function updateItemBy(collection, predicate, newItem) {
1623
- const itemIndex = collection.findIndex(predicate);
1624
- if (itemIndex !== CommonConstants.NOT_FOUND_INDEX) {
1625
- const result = collection.slice(0);
1626
- result[itemIndex] = {
1627
- ...collection[itemIndex],
1628
- ...newItem
1629
- };
1630
- return result;
1698
+ function removeClasses(element, ...classNames) {
1699
+ if (isDefined(element)) {
1700
+ classNames.forEach((className) => element.classList.remove(className));
1631
1701
  }
1632
- return null;
1633
1702
  }
1634
1703
  /**
1635
- * Return collection or empty if collection is not defined
1636
- * @param collection Array of items
1637
- * @returns Collection or empty
1704
+ * Convert RGB color to HEX
1705
+ * @param r Red
1706
+ * @param g Green
1707
+ * @param b Blue
1708
+ * @returns HEX value
1638
1709
  */
1639
- function getCollectionOrEmpty(collection) {
1640
- return isDefined(collection) ? collection : [];
1710
+ function rgbToHex(r, g, b) {
1711
+ return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
1641
1712
  }
1642
1713
  /**
1643
- * Check if arrays are equal
1644
- * @param a First array
1645
- * @param b Second array
1646
- * @returns True if arrays are equal
1714
+ * Convert HEX to RGB value
1715
+ * @param hex HEX value
1716
+ * @returns RGB value
1647
1717
  */
1648
- function isArraysEquals(a, b) {
1649
- if (a.length !== b.length)
1650
- return false;
1651
- a.sort();
1652
- b.sort();
1653
- for (let i = 0; i < a.length; i++) {
1654
- if (a[i] !== b[i])
1655
- return false;
1718
+ function hexToRgb(hex) {
1719
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1720
+ if (result) {
1721
+ var r = parseInt(result[1], 16);
1722
+ var g = parseInt(result[2], 16);
1723
+ var b = parseInt(result[3], 16);
1724
+ return `rgb(${r}, ${g}, ${b})`;
1656
1725
  }
1657
- return true;
1726
+ return null;
1727
+ }
1728
+ /**
1729
+ * Set opacity for RGB value
1730
+ * @param rgb Rgb value with {opacity} placeholder
1731
+ * @param opacity Opacity value
1732
+ * @returns RGB value with relevant opacity
1733
+ */
1734
+ function replaceRgbOpacity(rgb, opacity) {
1735
+ return rgb.replace(UIConstants.RGB_OPACITY_PLACEHOLDER, opacity.toString());
1658
1736
  }
1659
1737
 
1660
1738
  /**
@@ -3234,7 +3312,7 @@ class LoadContainerComponent {
3234
3312
  })), loader$ = this.pagination ? pagination$ : more$;
3235
3313
  return loader$.pipe(map(() => ({ params: params, page: this.page })));
3236
3314
  }));
3237
- return combineLatest([this.sortingService.sorting$.pipe(startWith(this.model.sorting)), parameters$]).pipe(tap(() => this.loading = true), map(([sorting, parameters]) => ({ params: parameters.params, page: parameters.page, sorting: sorting })));
3315
+ return combineLatest([this.sortingService.sorting$.pipe(startWith(this.model.sorting)), parameters$]).pipe(tap(() => this.loading = true), map(([sorting, parameters]) => ({ params: parameters.params, page: parameters.page, size: this.model.pagination?.size, sorting: sorting })));
3238
3316
  }
3239
3317
  buildDynamic(parameters$, loader) {
3240
3318
  return parameters$.pipe(switchMap((parameters) => loader(parameters)), map((model) => ({ ...model, reset: this.reset, page: this.page })));
@@ -3246,7 +3324,7 @@ class LoadContainerComponent {
3246
3324
  if (this.source == LoadContainerChangesSource.Data
3247
3325
  && parameters.page != LoadMoreService.START_PAGE) {
3248
3326
  this.resetParameters();
3249
- parameters = { params: parameters.params, page: this.page, sorting: parameters.sorting };
3327
+ parameters = { params: parameters.params, page: this.page, size: this.model.pagination?.size, sorting: parameters.sorting };
3250
3328
  }
3251
3329
  const filtered = model.filter ? model.filter(items, parameters) : items, sorted = parameters.sorting ? sortBy([...filtered], parameters.sorting.id, parameters.sorting.direction) : filtered, data = sorted ? {
3252
3330
  items: this.model.pagination ? skip(sorted, parameters.page, this.model.pagination?.size) : sorted,
@@ -3445,28 +3523,34 @@ TagConstants.DEFAULT_LABEL = 'Tag';
3445
3523
 
3446
3524
  class TagComponent {
3447
3525
  constructor() {
3448
- this.close = false;
3526
+ this.remove = false;
3449
3527
  this.model = {
3450
3528
  key: CommonConstants.DEFAULT_KEY_VALUE,
3451
3529
  label: TagConstants.DEFAULT_LABEL
3452
3530
  };
3453
- this.remove = new EventEmitter();
3531
+ this.removeAction = new EventEmitter();
3454
3532
  }
3533
+ _onClick() { if (this.model.click)
3534
+ this.model.click(this.model); }
3455
3535
  onRemove() {
3456
- this.remove.emit(this.model);
3536
+ this.removeAction.emit(this.model);
3457
3537
  }
3458
3538
  }
3459
3539
  TagComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: TagComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
3460
- TagComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.4", type: TagComponent, selector: "sfc-tag1", inputs: { close: "close", model: "model" }, outputs: { remove: "remove" }, ngImport: i0, template: "<div class=\"container\">\r\n <div class=\"content\">\r\n <sfc-icon *ngIf=\"model.icon || model.imageSrc\" [icon]=\"model.icon\" [imageSrc]=\"model.imageSrc\"></sfc-icon>\r\n <span>{{model.label}}</span>\r\n <sfc-close *ngIf=\"close\" (click)=\"onRemove()\"></sfc-close>\r\n </div>\r\n</div>", styles: [":host{display:inline-block}:host .container .content{display:flex;align-items:center;text-align:center;padding:.3em .8em;display:inline-flex;border-radius:1em;font-weight:700;-webkit-user-select:none;user-select:none;transition:color .5s ease;transition:background-color .5s ease;transition:color .5s ease,background-color .5s ease;border:.125em solid transparent}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{color:#fff}:host-context(.sfc-dark-theme) :host .container .content{color:#545e61}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{background-color:#545e61}:host-context(.sfc-dark-theme) :host .container .content{background-color:#fff}:host .container .content sfc-icon{margin-right:.2em}:host .container .content sfc-icon ::ng-deep .container img{max-width:1em;max-height:1em}:host .container .content sfc-close{margin-left:.4em;color:#ed5565;font-size:.8em}:host:hover .container .content{background-color:#ffce54;color:#fff}\n"], dependencies: [{ kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: CloseComponent, selector: "sfc-close" }, { kind: "component", type: IconComponent, selector: "sfc-icon", inputs: ["icon", "imageSrc"] }] });
3540
+ TagComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.4", type: TagComponent, selector: "sfc-tag", inputs: { remove: "remove", model: "model" }, outputs: { removeAction: "remove" }, host: { listeners: { "click": "_onClick()" } }, ngImport: i0, template: "<div class=\"container\">\r\n <div class=\"content\">\r\n <sfc-icon *ngIf=\"model.icon || model.imageSrc\" [icon]=\"model.icon\" [imageSrc]=\"model.imageSrc\"></sfc-icon>\r\n <span>{{model.label}}</span>\r\n <sfc-close *ngIf=\"model.remove\" (click)=\"onRemove()\"></sfc-close>\r\n </div>\r\n</div>", styles: [":host{display:inline-block}:host .container .content{display:flex;align-items:center;text-align:center;padding:.3em .8em;display:inline-flex;border-radius:1em;font-weight:700;-webkit-user-select:none;user-select:none;transition:color .5s ease;transition:background-color .5s ease;transition:color .5s ease,background-color .5s ease,border-color .5s ease;border:.125em solid transparent}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{color:#fff}:host-context(.sfc-dark-theme) :host .container .content{color:#545e61}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{background-color:#545e61}:host-context(.sfc-dark-theme) :host .container .content{background-color:#fff}:host .container .content sfc-icon{margin-right:.2em}:host .container .content sfc-icon ::ng-deep .container img{max-width:1em;max-height:1em}:host .container .content sfc-close{margin-left:.6em;color:#ed5565;font-size:.8em}:host:hover .container .content{background-color:#ffce54;color:#fff}\n"], dependencies: [{ kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: CloseComponent, selector: "sfc-close" }, { kind: "component", type: IconComponent, selector: "sfc-icon", inputs: ["icon", "imageSrc"] }] });
3461
3541
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: TagComponent, decorators: [{
3462
3542
  type: Component,
3463
- args: [{ selector: 'sfc-tag1', template: "<div class=\"container\">\r\n <div class=\"content\">\r\n <sfc-icon *ngIf=\"model.icon || model.imageSrc\" [icon]=\"model.icon\" [imageSrc]=\"model.imageSrc\"></sfc-icon>\r\n <span>{{model.label}}</span>\r\n <sfc-close *ngIf=\"close\" (click)=\"onRemove()\"></sfc-close>\r\n </div>\r\n</div>", styles: [":host{display:inline-block}:host .container .content{display:flex;align-items:center;text-align:center;padding:.3em .8em;display:inline-flex;border-radius:1em;font-weight:700;-webkit-user-select:none;user-select:none;transition:color .5s ease;transition:background-color .5s ease;transition:color .5s ease,background-color .5s ease;border:.125em solid transparent}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{color:#fff}:host-context(.sfc-dark-theme) :host .container .content{color:#545e61}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{background-color:#545e61}:host-context(.sfc-dark-theme) :host .container .content{background-color:#fff}:host .container .content sfc-icon{margin-right:.2em}:host .container .content sfc-icon ::ng-deep .container img{max-width:1em;max-height:1em}:host .container .content sfc-close{margin-left:.4em;color:#ed5565;font-size:.8em}:host:hover .container .content{background-color:#ffce54;color:#fff}\n"] }]
3464
- }], propDecorators: { close: [{
3543
+ args: [{ selector: 'sfc-tag', template: "<div class=\"container\">\r\n <div class=\"content\">\r\n <sfc-icon *ngIf=\"model.icon || model.imageSrc\" [icon]=\"model.icon\" [imageSrc]=\"model.imageSrc\"></sfc-icon>\r\n <span>{{model.label}}</span>\r\n <sfc-close *ngIf=\"model.remove\" (click)=\"onRemove()\"></sfc-close>\r\n </div>\r\n</div>", styles: [":host{display:inline-block}:host .container .content{display:flex;align-items:center;text-align:center;padding:.3em .8em;display:inline-flex;border-radius:1em;font-weight:700;-webkit-user-select:none;user-select:none;transition:color .5s ease;transition:background-color .5s ease;transition:color .5s ease,background-color .5s ease,border-color .5s ease;border:.125em solid transparent}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{color:#fff}:host-context(.sfc-dark-theme) :host .container .content{color:#545e61}:host .container .content,:host-context(.sfc-default-theme) :host .container .content{background-color:#545e61}:host-context(.sfc-dark-theme) :host .container .content{background-color:#fff}:host .container .content sfc-icon{margin-right:.2em}:host .container .content sfc-icon ::ng-deep .container img{max-width:1em;max-height:1em}:host .container .content sfc-close{margin-left:.6em;color:#ed5565;font-size:.8em}:host:hover .container .content{background-color:#ffce54;color:#fff}\n"] }]
3544
+ }], propDecorators: { remove: [{
3465
3545
  type: Input
3466
3546
  }], model: [{
3467
3547
  type: Input
3468
- }], remove: [{
3469
- type: Output
3548
+ }], removeAction: [{
3549
+ type: Output,
3550
+ args: ['remove']
3551
+ }], _onClick: [{
3552
+ type: HostListener,
3553
+ args: ['click']
3470
3554
  }] } });
3471
3555
 
3472
3556
  class NgxSfcCommonModule {
@@ -3695,5 +3779,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImpor
3695
3779
  * Generated bundle index. Do not edit.
3696
3780
  */
3697
3781
 
3698
- export { BounceLoaderComponent, BrowserDocumentRef, BrowserWindowRef, ButtonComponent, ButtonType, CheckmarkComponent, CheckmarkType, CircleLoaderComponent, CircleLoaderType, ClickOutsideDirective, CloseComponent, CollapseExpandComponent, CollapseExpandContainerComponent, CollapseExpandDirective, CommonConstants, Compare, ComponentReferenceDirective, ComponentSize, ComponentSizeDirective, DOCUMENT, DOCUMENT_PROVIDERS, DateTimeConstants, DefaultModalFooterComponent, DefaultModalHeaderComponent, DelimeterComponent, DestroyParentDirective, Direction, DocumentRef, DomChangesDirective, DotComponent, DotsComponent, HamburgerComponent, HamburgerMenuComponent, IconComponent, IfDirective, ImageLoadDirective, ImageLoadService, ItemsView, LoadContainerChangesSource, LoadContainerComponent, LoadContainerLoadType, LoadContainerType, LoadMoreButtonComponent, LoadMoreService, LoaderService, MediaLimits, MessageComponent, ModalComponent, ModalOpenDirective, ModalOpenOnClickDirective, ModalService, ModalTemplate, MouseDownDirective, NgxSfcCommonModule, NotificationType, ObservableBehaviorModel, ObservableModel, PaginationComponent, PaginationConstants, PaginationService, Position, ReloadService, RepeatPipe, ResizeService, ScrollIntoViewDirective, ScrollTrackerDirective, Select, Sequence, ShowHideElementDirective, SortByPipe, SortingDirection, SortingService, State, SwitchMultiCasePipe, TagComponent, TemplateContentComponent, TemplateReferenceDirective, Theme, ThrowElementOnHoverDirective, ToggleComponent, ToggleSwitcherComponent, TooltipComponent, TooltipType, UIClass, UIConstants, WINDOW, WINDOW_PROVIDERS, WindowRef, addClasses, addItem, addPropertyToObject, all, any, browserDocumentProvider, browserWindowProvider, buildHttpParams, contains, convertDateToTimestamp, convertFromBase64String, convertTimestampToDate, convertToBase64String, convertUTCDateToLocalDate, count, distinct, documentFactory, documentProvider, firstItem, firstOrDefault, generateGuid, getAge, getCalcValue, getCollectionOrEmpty, getCssLikeValue, getFileExtension, getFirstDayOfMonth, getFirstDayOfMonthByYearAndMonth, getFirstDayOfYear, getLastDayOfMonth, getLastDayOfMonthByYearAndMonth, getLastDayOfYear, getNextDate, getNextMonth, getNextYear, getPreviousDate, getPreviousMonth, getPreviousYear, getRotateValue, getValueFromCssLikeValue, getWeeksNumberInMonth, hasAnyItem, hasItem, hasItemBy, hasObjectItem, hexToRgb, isArraysEquals, isAsyncData, isChromeBrowser, isDateGreat, isDateGreatOrEqual, isDateTimeGreat, isDateTimeGreatOrEqual, isDateTimeLessOrEqual, isDefined, isEmail, isEqual, isEqualDateTimes, isEqualDates, isImage, isJsonString, isNullOrEmptyString, isNumeric, isObject, isString, isTimeGreatOrEqual, isTimeLessOrEqual, lastItem, max, mergeDeep, nameof, parseBoolean, parseFileSize, readAsDataURL, remove, removeClasses, removeItem, removeItemBy, removePropertyFromObject, replaceRgbOpacity, rgbToHex, setDay, setDefaultSecondsAndMiliseconds, setHours, setMilliseconds, setMinutes, setSeconds, setYear, skip, sort, sortBy, sortByPath, stopAndPreventPropagation, sum, trim, updateItemBy, where, windowFactory, windowProvider };
3782
+ export { BounceLoaderComponent, BrowserDocumentRef, BrowserWindowRef, ButtonComponent, ButtonType, CheckmarkComponent, CheckmarkType, CircleLoaderComponent, CircleLoaderType, ClickOutsideDirective, CloseComponent, CollapseExpandComponent, CollapseExpandContainerComponent, CollapseExpandDirective, CommonConstants, Compare, ComponentReferenceDirective, ComponentSize, ComponentSizeDirective, DOCUMENT, DOCUMENT_PROVIDERS, DateTimeConstants, DefaultModalFooterComponent, DefaultModalHeaderComponent, DelimeterComponent, DestroyParentDirective, Direction, DocumentRef, DomChangesDirective, DotComponent, DotsComponent, HamburgerComponent, HamburgerMenuComponent, IconComponent, IfDirective, ImageLoadDirective, ImageLoadService, ItemsView, LoadContainerChangesSource, LoadContainerComponent, LoadContainerLoadType, LoadContainerType, LoadMoreButtonComponent, LoadMoreService, LoaderService, MediaLimits, MessageComponent, ModalComponent, ModalOpenDirective, ModalOpenOnClickDirective, ModalService, ModalTemplate, MouseDownDirective, NgxSfcCommonModule, NotificationType, ObservableBehaviorModel, ObservableModel, PaginationComponent, PaginationConstants, PaginationService, Position, ReloadService, RepeatPipe, ResizeService, ScrollIntoViewDirective, ScrollTrackerDirective, Select, Sequence, ShowHideElementDirective, SortByPipe, SortingDirection, SortingService, State, SwitchMultiCasePipe, TagComponent, TemplateContentComponent, TemplateReferenceDirective, Theme, ThrowElementOnHoverDirective, ToggleComponent, ToggleSwitcherComponent, TooltipComponent, TooltipType, UIClass, UIConstants, WINDOW, WINDOW_PROVIDERS, WindowRef, addClasses, addItem, addPropertyToObject, all, any, browserDocumentProvider, browserWindowProvider, buildHttpParams, contains, convertDateToTimestamp, convertFromBase64String, convertTimestampToDate, convertToBase64String, convertUTCDateToLocalDate, count, deepClone, distinct, documentFactory, documentProvider, findChangedPropertyKey, findChangedPropertyPath, firstItem, firstOrDefault, generateGuid, getAge, getCalcValue, getCollectionOrEmpty, getCssLikeValue, getFileExtension, getFirstDayOfMonth, getFirstDayOfMonthByYearAndMonth, getFirstDayOfYear, getLastDayOfMonth, getLastDayOfMonthByYearAndMonth, getLastDayOfYear, getNextDate, getNextMonth, getNextYear, getPreviousDate, getPreviousMonth, getPreviousYear, getRotateValue, getValueFromCssLikeValue, getWeeksNumberInMonth, hasAnyItem, hasItem, hasItemBy, hasObjectItem, hexToRgb, isArraysEquals, isAsyncData, isChromeBrowser, isDateGreat, isDateGreatOrEqual, isDateTimeGreat, isDateTimeGreatOrEqual, isDateTimeLessOrEqual, isDefined, isEmail, isEqual, isEqualDateTimes, isEqualDates, isImage, isJsonString, isNullOrEmptyString, isNumeric, isObject, isString, isTimeGreatOrEqual, isTimeLessOrEqual, lastItem, max, mergeDeep, nameof, parseBoolean, parseFileSize, readAsDataURL, remove, removeClasses, removeItem, removeItemBy, removePropertyFromObject, replaceRgbOpacity, rgbToHex, setDay, setDefaultSecondsAndMiliseconds, setHours, setMilliseconds, setMinutes, setSeconds, setYear, skip, sort, sortBy, sortByPath, stopAndPreventPropagation, sum, trim, updateItemBy, updatePropertyByKey, where, windowFactory, windowProvider };
3783
+ //# sourceMappingURL=ngx-sfc-common.mjs.map
3699
3784
  //# sourceMappingURL=ngx-sfc-common.mjs.map