@lowentry/utils 1.12.2 → 1.13.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowentry/utils",
3
- "version": "1.12.2",
3
+ "version": "1.13.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/LeUtils.js CHANGED
@@ -640,9 +640,10 @@ export const LeUtils = {
640
640
  */
641
641
  /**
642
642
  * Loops through the given elements, and returns a new array or object, with only the elements that returned true (or a value equals to true) from the callback.
643
+ * If no callback is given, it will return all elements that are of a true value (for example, values that are: not null, not undefined, not false, not 0, not an empty string, not an empty array, not an empty object).
643
644
  *
644
645
  * @param {*[]|object|Function} elements
645
- * @param {LeUtils~__filterCallback} callback
646
+ * @param {LeUtils~__filterCallback} [callback]
646
647
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
647
648
  * @returns {*[]|object|Function}
648
649
  */
@@ -656,7 +657,7 @@ export const LeUtils = {
656
657
  let result = [];
657
658
  for(let index = 0; index < elements.length; index++)
658
659
  {
659
- if(!callback.call(elements[index], elements[index], index))
660
+ if((!callback && elements[index]) || (callback && callback.call(elements[index], elements[index], index)))
660
661
  {
661
662
  result.push(elements[index]);
662
663
  }
@@ -670,7 +671,7 @@ export const LeUtils = {
670
671
  {
671
672
  if((optionalSkipHasOwnPropertyCheck === true) || Object.prototype.hasOwnProperty.call(elements, index))
672
673
  {
673
- if(!callback.call(elements[index], elements[index], index))
674
+ if((!callback && elements[index]) || (callback && callback.call(elements[index], elements[index], index)))
674
675
  {
675
676
  result[index] = elements[index];
676
677
  }
@@ -696,7 +697,7 @@ export const LeUtils = {
696
697
  * Loops through the given elements, and returns a new array or object, with the elements that were returned from the callback.
697
698
  *
698
699
  * @param {*[]|object|Function} elements
699
- * @param {LeUtils~__mapCallback} callback
700
+ * @param {LeUtils~__mapCallback} [callback]
700
701
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
701
702
  * @returns {*[]|object|Function}
702
703
  */
@@ -710,7 +711,14 @@ export const LeUtils = {
710
711
  let result = [];
711
712
  for(let index = 0; index < elements.length; index++)
712
713
  {
713
- result[index] = callback.call(elements[index], elements[index], index);
714
+ if(!callback)
715
+ {
716
+ result[index] = elements[index];
717
+ }
718
+ else
719
+ {
720
+ result[index] = callback.call(elements[index], elements[index], index);
721
+ }
714
722
  }
715
723
  return result;
716
724
  }
@@ -721,7 +729,14 @@ export const LeUtils = {
721
729
  {
722
730
  if((optionalSkipHasOwnPropertyCheck === true) || Object.prototype.hasOwnProperty.call(elements, index))
723
731
  {
724
- result[index] = callback.call(elements[index], elements[index], index);
732
+ if(!callback)
733
+ {
734
+ result[index] = elements[index];
735
+ }
736
+ else
737
+ {
738
+ result[index] = callback.call(elements[index], elements[index], index);
739
+ }
725
740
  }
726
741
  }
727
742
  return result;
@@ -744,7 +759,7 @@ export const LeUtils = {
744
759
  * Loops through the given elements, and returns a new array, with the elements that were returned from the callback. Always returns an array.
745
760
  *
746
761
  * @param {*[]|object|Function} elements
747
- * @param {LeUtils~__mapToArrayCallback} callback
762
+ * @param {LeUtils~__mapToArrayCallback} [callback]
748
763
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
749
764
  * @returns {*[]}
750
765
  */
@@ -758,7 +773,14 @@ export const LeUtils = {
758
773
  {
759
774
  for(let index = 0; index < elements.length; index++)
760
775
  {
761
- result.push(callback.call(elements[index], elements[index], index));
776
+ if(!callback)
777
+ {
778
+ result.push(elements[index]);
779
+ }
780
+ else
781
+ {
782
+ result.push(callback.call(elements[index], elements[index], index));
783
+ }
762
784
  }
763
785
  }
764
786
  else if((typeof elements === 'object') || (typeof elements === 'function'))
@@ -767,7 +789,14 @@ export const LeUtils = {
767
789
  {
768
790
  if((optionalSkipHasOwnPropertyCheck === true) || Object.prototype.hasOwnProperty.call(elements, index))
769
791
  {
770
- result.push(callback.call(elements[index], elements[index], index));
792
+ if(!callback)
793
+ {
794
+ result.push(elements[index]);
795
+ }
796
+ else
797
+ {
798
+ result.push(callback.call(elements[index], elements[index], index));
799
+ }
771
800
  }
772
801
  }
773
802
  }
@@ -790,7 +819,7 @@ export const LeUtils = {
790
819
  *
791
820
  * @param {*[]|object|Function} elements
792
821
  * @param {LeUtils~__sortKeysComparatorCallback} comparator
793
- * @param {LeUtils~__mapToArraySortedCallback} callback
822
+ * @param {LeUtils~__mapToArraySortedCallback} [callback]
794
823
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
795
824
  * @returns {*[]}
796
825
  */
@@ -801,7 +830,14 @@ export const LeUtils = {
801
830
  let result = [];
802
831
  for(let i = 0; i < keys.length; i++)
803
832
  {
804
- result.push(callback.call(elements[keys[i]], elements[keys[i]], keys[i]));
833
+ if(!callback)
834
+ {
835
+ result.push(elements[keys[i]]);
836
+ }
837
+ else
838
+ {
839
+ result.push(callback.call(elements[keys[i]], elements[keys[i]], keys[i]));
840
+ }
805
841
  }
806
842
  return result;
807
843
  },