@lowentry/utils 1.11.5 → 1.12.2
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 +62 -3
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeUtils.js +60 -3
package/index.js
CHANGED
|
@@ -542,10 +542,64 @@ var LeUtils = {
|
|
|
542
542
|
});
|
|
543
543
|
return result;
|
|
544
544
|
},
|
|
545
|
+
/**
|
|
546
|
+
* @callback LeUtils~__findIndexValueCallback
|
|
547
|
+
* @param {*} value
|
|
548
|
+
* @param {*} index
|
|
549
|
+
* @returns {boolean|undefined}
|
|
550
|
+
*/
|
|
551
|
+
/**
|
|
552
|
+
* Finds the first element in the given array or object that returns true from the callback, and returns an object with the index and value.
|
|
553
|
+
*
|
|
554
|
+
* @param {*[]|object|Function} elements
|
|
555
|
+
* @param {LeUtils~__findIndexValueCallback} callback
|
|
556
|
+
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
557
|
+
* @returns {{index:*, value:*}|null}
|
|
558
|
+
*/
|
|
559
|
+
findIndexValue: function findIndexValue(elements, callback) {
|
|
560
|
+
var result = null;
|
|
561
|
+
LeUtils.each(elements, function (value, index) {
|
|
562
|
+
if (callback.call(elements[index], elements[index], index)) {
|
|
563
|
+
result = {
|
|
564
|
+
index: index,
|
|
565
|
+
value: value
|
|
566
|
+
};
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
return result;
|
|
571
|
+
},
|
|
572
|
+
/**
|
|
573
|
+
* Finds the first element in the given array or object that returns true from the callback, and returns the index.
|
|
574
|
+
*
|
|
575
|
+
* @param {*[]|object|Function} elements
|
|
576
|
+
* @param {LeUtils~__findIndexValueCallback} callback
|
|
577
|
+
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
578
|
+
* @returns {*|null}
|
|
579
|
+
*/
|
|
580
|
+
findIndex: function findIndex(elements, callback) {
|
|
581
|
+
var _LeUtils$findIndexVal, _LeUtils$findIndexVal2;
|
|
582
|
+
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
583
|
+
return (_LeUtils$findIndexVal = (_LeUtils$findIndexVal2 = LeUtils.findIndexValue(elements, callback, optionalSkipHasOwnPropertyCheck)) === null || _LeUtils$findIndexVal2 === void 0 ? void 0 : _LeUtils$findIndexVal2.index) !== null && _LeUtils$findIndexVal !== void 0 ? _LeUtils$findIndexVal : null;
|
|
584
|
+
},
|
|
585
|
+
/**
|
|
586
|
+
* Finds the first element in the given array or object that returns true from the callback, and returns the value.
|
|
587
|
+
*
|
|
588
|
+
* @param {*[]|object|Function} elements
|
|
589
|
+
* @param {LeUtils~__findIndexValueCallback} callback
|
|
590
|
+
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
591
|
+
* @returns {*|null}
|
|
592
|
+
*/
|
|
593
|
+
find: function find(elements, callback) {
|
|
594
|
+
var _LeUtils$findIndexVal3, _LeUtils$findIndexVal4;
|
|
595
|
+
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
596
|
+
return (_LeUtils$findIndexVal3 = (_LeUtils$findIndexVal4 = LeUtils.findIndexValue(elements, callback, optionalSkipHasOwnPropertyCheck)) === null || _LeUtils$findIndexVal4 === void 0 ? void 0 : _LeUtils$findIndexVal4.value) !== null && _LeUtils$findIndexVal3 !== void 0 ? _LeUtils$findIndexVal3 : null;
|
|
597
|
+
},
|
|
545
598
|
/**
|
|
546
599
|
* @callback LeUtils~__eachCallback
|
|
547
600
|
* @param {*} value
|
|
548
601
|
* @param {*} index
|
|
602
|
+
* @returns {boolean|undefined}
|
|
549
603
|
*/
|
|
550
604
|
/**
|
|
551
605
|
* Loops through each element in the given array or object, and calls the callback for each element.
|
|
@@ -792,9 +846,10 @@ var LeUtils = {
|
|
|
792
846
|
* @callback LeUtils~__filterCallback
|
|
793
847
|
* @param {*} value
|
|
794
848
|
* @param {*} index
|
|
849
|
+
* @returns {boolean|undefined}
|
|
795
850
|
*/
|
|
796
851
|
/**
|
|
797
|
-
* Loops through the given elements, and returns a new array or object, with only the elements that
|
|
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.
|
|
798
853
|
*
|
|
799
854
|
* @param {*[]|object|Function} elements
|
|
800
855
|
* @param {LeUtils~__filterCallback} callback
|
|
@@ -807,7 +862,7 @@ var LeUtils = {
|
|
|
807
862
|
if (Array.isArray(elements)) {
|
|
808
863
|
var result = [];
|
|
809
864
|
for (var index = 0; index < elements.length; index++) {
|
|
810
|
-
if (callback.call(elements[index], elements[index], index)
|
|
865
|
+
if (!callback.call(elements[index], elements[index], index)) {
|
|
811
866
|
result.push(elements[index]);
|
|
812
867
|
}
|
|
813
868
|
}
|
|
@@ -816,7 +871,7 @@ var LeUtils = {
|
|
|
816
871
|
var _result = {};
|
|
817
872
|
for (var _index3 in elements) {
|
|
818
873
|
if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index3)) {
|
|
819
|
-
if (callback.call(elements[_index3], elements[_index3], _index3)
|
|
874
|
+
if (!callback.call(elements[_index3], elements[_index3], _index3)) {
|
|
820
875
|
_result[_index3] = elements[_index3];
|
|
821
876
|
}
|
|
822
877
|
}
|
|
@@ -832,6 +887,7 @@ var LeUtils = {
|
|
|
832
887
|
* @callback LeUtils~__mapCallback
|
|
833
888
|
* @param {*} value
|
|
834
889
|
* @param {*} index
|
|
890
|
+
* @returns {*}
|
|
835
891
|
*/
|
|
836
892
|
/**
|
|
837
893
|
* Loops through the given elements, and returns a new array or object, with the elements that were returned from the callback.
|
|
@@ -868,6 +924,7 @@ var LeUtils = {
|
|
|
868
924
|
* @callback LeUtils~__mapToArrayCallback
|
|
869
925
|
* @param {*} value
|
|
870
926
|
* @param {*} index
|
|
927
|
+
* @returns {*}
|
|
871
928
|
*/
|
|
872
929
|
/**
|
|
873
930
|
* Loops through the given elements, and returns a new array, with the elements that were returned from the callback. Always returns an array.
|
|
@@ -901,6 +958,7 @@ var LeUtils = {
|
|
|
901
958
|
* @callback LeUtils~__mapToArraySortedCallback
|
|
902
959
|
* @param {*} value
|
|
903
960
|
* @param {*} index
|
|
961
|
+
* @returns {*}
|
|
904
962
|
*/
|
|
905
963
|
/**
|
|
906
964
|
* Loops through the given elements, and returns a new array, with the elements that were returned from the callback. The elements will be sorted by the result from the given comparator. Always returns an array.
|
|
@@ -924,6 +982,7 @@ var LeUtils = {
|
|
|
924
982
|
* @callback LeUtils~__sortKeysComparatorCallback
|
|
925
983
|
* @param {*} elementA
|
|
926
984
|
* @param {*} elementB
|
|
985
|
+
* @returns {number}
|
|
927
986
|
*/
|
|
928
987
|
/**
|
|
929
988
|
* Loops through the given elements, and returns a new array, with the keys from the given elements, sorted by the result from the given comparator. Always returns an array.
|