@lowentry/utils 1.12.3 → 1.13.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 +52 -32
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeUtils.js +43 -8
package/index.js
CHANGED
|
@@ -271,19 +271,19 @@ var LeUtils = {
|
|
|
271
271
|
return LeUtils.setTimeout(callback, 0);
|
|
272
272
|
} else {
|
|
273
273
|
var listening = true;
|
|
274
|
-
var
|
|
274
|
+
var _callbackWrapper = function callbackWrapper() {
|
|
275
275
|
if (listening) {
|
|
276
276
|
listening = false;
|
|
277
|
-
document.removeEventListener('DOMContentLoaded',
|
|
277
|
+
document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
278
278
|
callback();
|
|
279
279
|
}
|
|
280
280
|
};
|
|
281
|
-
document.addEventListener('DOMContentLoaded',
|
|
281
|
+
document.addEventListener('DOMContentLoaded', _callbackWrapper);
|
|
282
282
|
return {
|
|
283
283
|
remove: function remove() {
|
|
284
284
|
if (listening) {
|
|
285
285
|
listening = false;
|
|
286
|
-
document.removeEventListener('DOMContentLoaded',
|
|
286
|
+
document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
};
|
|
@@ -643,7 +643,7 @@ var LeUtils = {
|
|
|
643
643
|
*/
|
|
644
644
|
eachAsync: function () {
|
|
645
645
|
var eachAsyncParallel = /*#__PURE__*/function () {
|
|
646
|
-
var _ref2 = _asyncToGenerator(
|
|
646
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(elements, asyncCallback, optionalParallelCount, optionalSkipHasOwnPropertyCheck) {
|
|
647
647
|
var promises, doBreak;
|
|
648
648
|
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
649
649
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -652,7 +652,7 @@ var LeUtils = {
|
|
|
652
652
|
doBreak = false;
|
|
653
653
|
_context4.next = 4;
|
|
654
654
|
return LeUtils.eachAsync(elements, /*#__PURE__*/function () {
|
|
655
|
-
var _ref3 = _asyncToGenerator(
|
|
655
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(element, index) {
|
|
656
656
|
var _loop, promise;
|
|
657
657
|
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
658
658
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -697,7 +697,7 @@ var LeUtils = {
|
|
|
697
697
|
}
|
|
698
698
|
return _context3.abrupt("return", false);
|
|
699
699
|
case 7:
|
|
700
|
-
promise = _asyncToGenerator(
|
|
700
|
+
promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
701
701
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
702
702
|
while (1) switch (_context.prev = _context.next) {
|
|
703
703
|
case 0:
|
|
@@ -745,7 +745,7 @@ var LeUtils = {
|
|
|
745
745
|
};
|
|
746
746
|
}();
|
|
747
747
|
return /*#__PURE__*/function () {
|
|
748
|
-
var _ref5 = _asyncToGenerator(
|
|
748
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(elements, asyncCallback) {
|
|
749
749
|
var parallelCount,
|
|
750
750
|
optionalSkipHasOwnPropertyCheck,
|
|
751
751
|
index,
|
|
@@ -894,7 +894,7 @@ var LeUtils = {
|
|
|
894
894
|
* Loops through the given elements, and returns a new array or object, with the elements that were returned from the callback.
|
|
895
895
|
*
|
|
896
896
|
* @param {*[]|object|Function} elements
|
|
897
|
-
* @param {LeUtils~__mapCallback} callback
|
|
897
|
+
* @param {LeUtils~__mapCallback} [callback]
|
|
898
898
|
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
899
899
|
* @returns {*[]|object|Function}
|
|
900
900
|
*/
|
|
@@ -904,14 +904,22 @@ var LeUtils = {
|
|
|
904
904
|
if (Array.isArray(elements)) {
|
|
905
905
|
var result = [];
|
|
906
906
|
for (var index = 0; index < elements.length; index++) {
|
|
907
|
-
|
|
907
|
+
if (!callback) {
|
|
908
|
+
result[index] = elements[index];
|
|
909
|
+
} else {
|
|
910
|
+
result[index] = callback.call(elements[index], elements[index], index);
|
|
911
|
+
}
|
|
908
912
|
}
|
|
909
913
|
return result;
|
|
910
914
|
} else if (_typeof(elements) === 'object' || typeof elements === 'function') {
|
|
911
915
|
var _result2 = {};
|
|
912
916
|
for (var _index4 in elements) {
|
|
913
917
|
if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index4)) {
|
|
914
|
-
|
|
918
|
+
if (!callback) {
|
|
919
|
+
_result2[_index4] = elements[_index4];
|
|
920
|
+
} else {
|
|
921
|
+
_result2[_index4] = callback.call(elements[_index4], elements[_index4], _index4);
|
|
922
|
+
}
|
|
915
923
|
}
|
|
916
924
|
}
|
|
917
925
|
return _result2;
|
|
@@ -931,7 +939,7 @@ var LeUtils = {
|
|
|
931
939
|
* Loops through the given elements, and returns a new array, with the elements that were returned from the callback. Always returns an array.
|
|
932
940
|
*
|
|
933
941
|
* @param {*[]|object|Function} elements
|
|
934
|
-
* @param {LeUtils~__mapToArrayCallback} callback
|
|
942
|
+
* @param {LeUtils~__mapToArrayCallback} [callback]
|
|
935
943
|
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
936
944
|
* @returns {*[]}
|
|
937
945
|
*/
|
|
@@ -941,12 +949,20 @@ var LeUtils = {
|
|
|
941
949
|
if (elements !== null && typeof elements !== 'undefined') {
|
|
942
950
|
if (Array.isArray(elements)) {
|
|
943
951
|
for (var index = 0; index < elements.length; index++) {
|
|
944
|
-
|
|
952
|
+
if (!callback) {
|
|
953
|
+
result.push(elements[index]);
|
|
954
|
+
} else {
|
|
955
|
+
result.push(callback.call(elements[index], elements[index], index));
|
|
956
|
+
}
|
|
945
957
|
}
|
|
946
958
|
} else if (_typeof(elements) === 'object' || typeof elements === 'function') {
|
|
947
959
|
for (var _index5 in elements) {
|
|
948
960
|
if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index5)) {
|
|
949
|
-
|
|
961
|
+
if (!callback) {
|
|
962
|
+
result.push(elements[_index5]);
|
|
963
|
+
} else {
|
|
964
|
+
result.push(callback.call(elements[_index5], elements[_index5], _index5));
|
|
965
|
+
}
|
|
950
966
|
}
|
|
951
967
|
}
|
|
952
968
|
} else {
|
|
@@ -966,7 +982,7 @@ var LeUtils = {
|
|
|
966
982
|
*
|
|
967
983
|
* @param {*[]|object|Function} elements
|
|
968
984
|
* @param {LeUtils~__sortKeysComparatorCallback} comparator
|
|
969
|
-
* @param {LeUtils~__mapToArraySortedCallback} callback
|
|
985
|
+
* @param {LeUtils~__mapToArraySortedCallback} [callback]
|
|
970
986
|
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
971
987
|
* @returns {*[]}
|
|
972
988
|
*/
|
|
@@ -975,7 +991,11 @@ var LeUtils = {
|
|
|
975
991
|
var keys = LeUtils.sortKeys(elements, comparator, optionalSkipHasOwnPropertyCheck);
|
|
976
992
|
var result = [];
|
|
977
993
|
for (var i = 0; i < keys.length; i++) {
|
|
978
|
-
|
|
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
|
+
}
|
|
979
999
|
}
|
|
980
1000
|
return result;
|
|
981
1001
|
},
|
|
@@ -1025,13 +1045,13 @@ var LeUtils = {
|
|
|
1025
1045
|
* @returns {*[]}
|
|
1026
1046
|
*/
|
|
1027
1047
|
flattenArray: function () {
|
|
1028
|
-
var
|
|
1048
|
+
var _flattenArrayRecursive = function flattenArrayRecursive(result, array) {
|
|
1029
1049
|
if (!Array.isArray(array)) {
|
|
1030
1050
|
result.push(array);
|
|
1031
1051
|
return;
|
|
1032
1052
|
}
|
|
1033
1053
|
array.forEach(function (entry) {
|
|
1034
|
-
|
|
1054
|
+
_flattenArrayRecursive(result, entry);
|
|
1035
1055
|
});
|
|
1036
1056
|
};
|
|
1037
1057
|
return function (array) {
|
|
@@ -1040,7 +1060,7 @@ var LeUtils = {
|
|
|
1040
1060
|
}
|
|
1041
1061
|
var result = [];
|
|
1042
1062
|
array.forEach(function (entry) {
|
|
1043
|
-
|
|
1063
|
+
_flattenArrayRecursive(result, entry);
|
|
1044
1064
|
});
|
|
1045
1065
|
return result;
|
|
1046
1066
|
};
|
|
@@ -1141,7 +1161,7 @@ var LeUtils = {
|
|
|
1141
1161
|
}
|
|
1142
1162
|
}, _callee5);
|
|
1143
1163
|
}).constructor;
|
|
1144
|
-
var AsyncGeneratorFunction = _wrapAsyncGenerator(
|
|
1164
|
+
var AsyncGeneratorFunction = _wrapAsyncGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
1145
1165
|
return _regeneratorRuntime.wrap(function _callee6$(_context7) {
|
|
1146
1166
|
while (1) switch (_context7.prev = _context7.next) {
|
|
1147
1167
|
case 0:
|
|
@@ -1293,7 +1313,7 @@ var LeUtils = {
|
|
|
1293
1313
|
var run = true;
|
|
1294
1314
|
var requestAnimationFrameId = null;
|
|
1295
1315
|
var lastTime = performance.now();
|
|
1296
|
-
var
|
|
1316
|
+
var _tick = function tick() {
|
|
1297
1317
|
if (run) {
|
|
1298
1318
|
if (frames <= 0) {
|
|
1299
1319
|
run = false;
|
|
@@ -1308,10 +1328,10 @@ var LeUtils = {
|
|
|
1308
1328
|
return;
|
|
1309
1329
|
}
|
|
1310
1330
|
frames--;
|
|
1311
|
-
requestAnimationFrameId = typeof window === 'undefined' ? setTimeout(
|
|
1331
|
+
requestAnimationFrameId = typeof window === 'undefined' ? setTimeout(_tick, 1000 / 60) : requestAnimationFrame(_tick);
|
|
1312
1332
|
}
|
|
1313
1333
|
};
|
|
1314
|
-
|
|
1334
|
+
_tick();
|
|
1315
1335
|
return {
|
|
1316
1336
|
remove: function remove() {
|
|
1317
1337
|
run = false;
|
|
@@ -1356,7 +1376,7 @@ var LeUtils = {
|
|
|
1356
1376
|
var requestAnimationFrameId = null;
|
|
1357
1377
|
var lastTime = performance.now();
|
|
1358
1378
|
var frames = intervalFrames;
|
|
1359
|
-
var
|
|
1379
|
+
var _tick2 = function tick() {
|
|
1360
1380
|
if (run) {
|
|
1361
1381
|
if (frames <= 0) {
|
|
1362
1382
|
var currentTime = performance.now();
|
|
@@ -1370,11 +1390,11 @@ var LeUtils = {
|
|
|
1370
1390
|
}
|
|
1371
1391
|
frames--;
|
|
1372
1392
|
if (run) {
|
|
1373
|
-
requestAnimationFrameId = typeof window === 'undefined' ? setTimeout(
|
|
1393
|
+
requestAnimationFrameId = typeof window === 'undefined' ? setTimeout(_tick2, 1000 / 60) : requestAnimationFrame(_tick2);
|
|
1374
1394
|
}
|
|
1375
1395
|
}
|
|
1376
1396
|
};
|
|
1377
|
-
typeof window === 'undefined' ? setTimeout(
|
|
1397
|
+
typeof window === 'undefined' ? setTimeout(_tick2, 1000 / 60) : requestAnimationFrame(_tick2);
|
|
1378
1398
|
return {
|
|
1379
1399
|
remove: function remove() {
|
|
1380
1400
|
run = false;
|
|
@@ -1442,13 +1462,13 @@ var LeUtils = {
|
|
|
1442
1462
|
if (typeof window !== 'undefined' && typeof window.AbortController !== 'undefined') {
|
|
1443
1463
|
controller = new AbortController();
|
|
1444
1464
|
}
|
|
1445
|
-
var promise = _asyncToGenerator(
|
|
1446
|
-
var
|
|
1465
|
+
var promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
1466
|
+
var _attemptFetch;
|
|
1447
1467
|
return _regeneratorRuntime.wrap(function _callee8$(_context9) {
|
|
1448
1468
|
while (1) switch (_context9.prev = _context9.next) {
|
|
1449
1469
|
case 0:
|
|
1450
|
-
|
|
1451
|
-
var _ref7 = _asyncToGenerator(
|
|
1470
|
+
_attemptFetch = /*#__PURE__*/function () {
|
|
1471
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
1452
1472
|
var _controller;
|
|
1453
1473
|
var _controller2, response, _controller3;
|
|
1454
1474
|
return _regeneratorRuntime.wrap(function _callee7$(_context8) {
|
|
@@ -1497,7 +1517,7 @@ var LeUtils = {
|
|
|
1497
1517
|
return LeUtils.promiseTimeout(typeof (options === null || options === void 0 ? void 0 : options.delay) === 'function' ? INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay(currentRetries), 500) : INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay, 500));
|
|
1498
1518
|
case 20:
|
|
1499
1519
|
_context8.next = 22;
|
|
1500
|
-
return
|
|
1520
|
+
return _attemptFetch();
|
|
1501
1521
|
case 22:
|
|
1502
1522
|
return _context8.abrupt("return", _context8.sent);
|
|
1503
1523
|
case 23:
|
|
@@ -1511,7 +1531,7 @@ var LeUtils = {
|
|
|
1511
1531
|
};
|
|
1512
1532
|
}();
|
|
1513
1533
|
_context9.next = 3;
|
|
1514
|
-
return
|
|
1534
|
+
return _attemptFetch();
|
|
1515
1535
|
case 3:
|
|
1516
1536
|
return _context9.abrupt("return", _context9.sent);
|
|
1517
1537
|
case 4:
|