@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/index.js CHANGED
@@ -850,9 +850,10 @@ var LeUtils = {
850
850
  */
851
851
  /**
852
852
  * 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.
853
+ * 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).
853
854
  *
854
855
  * @param {*[]|object|Function} elements
855
- * @param {LeUtils~__filterCallback} callback
856
+ * @param {LeUtils~__filterCallback} [callback]
856
857
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
857
858
  * @returns {*[]|object|Function}
858
859
  */
@@ -862,7 +863,7 @@ var LeUtils = {
862
863
  if (Array.isArray(elements)) {
863
864
  var result = [];
864
865
  for (var index = 0; index < elements.length; index++) {
865
- if (!callback.call(elements[index], elements[index], index)) {
866
+ if (!callback && elements[index] || callback && callback.call(elements[index], elements[index], index)) {
866
867
  result.push(elements[index]);
867
868
  }
868
869
  }
@@ -871,7 +872,7 @@ var LeUtils = {
871
872
  var _result = {};
872
873
  for (var _index3 in elements) {
873
874
  if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index3)) {
874
- if (!callback.call(elements[_index3], elements[_index3], _index3)) {
875
+ if (!callback && elements[_index3] || callback && callback.call(elements[_index3], elements[_index3], _index3)) {
875
876
  _result[_index3] = elements[_index3];
876
877
  }
877
878
  }
@@ -893,7 +894,7 @@ var LeUtils = {
893
894
  * Loops through the given elements, and returns a new array or object, with the elements that were returned from the callback.
894
895
  *
895
896
  * @param {*[]|object|Function} elements
896
- * @param {LeUtils~__mapCallback} callback
897
+ * @param {LeUtils~__mapCallback} [callback]
897
898
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
898
899
  * @returns {*[]|object|Function}
899
900
  */
@@ -903,14 +904,22 @@ var LeUtils = {
903
904
  if (Array.isArray(elements)) {
904
905
  var result = [];
905
906
  for (var index = 0; index < elements.length; index++) {
906
- result[index] = callback.call(elements[index], elements[index], index);
907
+ if (!callback) {
908
+ result[index] = elements[index];
909
+ } else {
910
+ result[index] = callback.call(elements[index], elements[index], index);
911
+ }
907
912
  }
908
913
  return result;
909
914
  } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
910
915
  var _result2 = {};
911
916
  for (var _index4 in elements) {
912
917
  if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index4)) {
913
- _result2[_index4] = callback.call(elements[_index4], elements[_index4], _index4);
918
+ if (!callback) {
919
+ _result2[_index4] = elements[_index4];
920
+ } else {
921
+ _result2[_index4] = callback.call(elements[_index4], elements[_index4], _index4);
922
+ }
914
923
  }
915
924
  }
916
925
  return _result2;
@@ -930,7 +939,7 @@ var LeUtils = {
930
939
  * Loops through the given elements, and returns a new array, with the elements that were returned from the callback. Always returns an array.
931
940
  *
932
941
  * @param {*[]|object|Function} elements
933
- * @param {LeUtils~__mapToArrayCallback} callback
942
+ * @param {LeUtils~__mapToArrayCallback} [callback]
934
943
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
935
944
  * @returns {*[]}
936
945
  */
@@ -940,12 +949,20 @@ var LeUtils = {
940
949
  if (elements !== null && typeof elements !== 'undefined') {
941
950
  if (Array.isArray(elements)) {
942
951
  for (var index = 0; index < elements.length; index++) {
943
- result.push(callback.call(elements[index], elements[index], index));
952
+ if (!callback) {
953
+ result.push(elements[index]);
954
+ } else {
955
+ result.push(callback.call(elements[index], elements[index], index));
956
+ }
944
957
  }
945
958
  } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
946
959
  for (var _index5 in elements) {
947
960
  if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index5)) {
948
- result.push(callback.call(elements[_index5], elements[_index5], _index5));
961
+ if (!callback) {
962
+ result.push(elements[_index5]);
963
+ } else {
964
+ result.push(callback.call(elements[_index5], elements[_index5], _index5));
965
+ }
949
966
  }
950
967
  }
951
968
  } else {
@@ -965,7 +982,7 @@ var LeUtils = {
965
982
  *
966
983
  * @param {*[]|object|Function} elements
967
984
  * @param {LeUtils~__sortKeysComparatorCallback} comparator
968
- * @param {LeUtils~__mapToArraySortedCallback} callback
985
+ * @param {LeUtils~__mapToArraySortedCallback} [callback]
969
986
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
970
987
  * @returns {*[]}
971
988
  */
@@ -974,7 +991,11 @@ var LeUtils = {
974
991
  var keys = LeUtils.sortKeys(elements, comparator, optionalSkipHasOwnPropertyCheck);
975
992
  var result = [];
976
993
  for (var i = 0; i < keys.length; i++) {
977
- result.push(callback.call(elements[keys[i]], elements[keys[i]], keys[i]));
994
+ if (!callback) {
995
+ result.push(elements[keys[i]]);
996
+ } else {
997
+ result.push(callback.call(elements[keys[i]], elements[keys[i]], keys[i]));
998
+ }
978
999
  }
979
1000
  return result;
980
1001
  },