@lowentry/utils 1.14.1 → 1.15.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
@@ -1,6 +1,7 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
4
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
5
  import _typeof from '@babel/runtime/helpers/typeof';
5
6
  import '@babel/runtime/helpers/awaitAsyncGenerator';
6
7
  import _wrapAsyncGenerator from '@babel/runtime/helpers/wrapAsyncGenerator';
@@ -207,9 +208,12 @@ var FLOAT_LAX_ANY = function FLOAT_LAX_ANY() {
207
208
 
208
209
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
209
210
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
211
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
212
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
213
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
210
214
 
211
215
  /**
212
- * @param {LeUtils~TransactionalValue} transactionalValue
216
+ * @param {LeUtils_TransactionalValue} transactionalValue
213
217
  */
214
218
  var checkTransactionalValue = function checkTransactionalValue(transactionalValue) {
215
219
  if (!LeUtils.isTransactionalValueValid(transactionalValue)) {
@@ -220,7 +224,7 @@ var checkTransactionalValue = function checkTransactionalValue(transactionalValu
220
224
  };
221
225
 
222
226
  /**
223
- * @param {LeUtils~TransactionalValue} transactionalValue
227
+ * @param {LeUtils_TransactionalValue} transactionalValue
224
228
  * @param {string} changeId
225
229
  * @returns {{index:number, value:*}|null}
226
230
  */
@@ -268,7 +272,9 @@ var LeUtils = {
268
272
  };
269
273
  }
270
274
  if (document.readyState === 'interactive' || document.readyState === 'complete') {
271
- return LeUtils.setTimeout(callback, 0);
275
+ return LeUtils.setTimeout(function () {
276
+ return callback();
277
+ }, 0);
272
278
  } else {
273
279
  var listening = true;
274
280
  var _callbackWrapper = function callbackWrapper() {
@@ -542,21 +548,16 @@ var LeUtils = {
542
548
  });
543
549
  return result;
544
550
  },
545
- /**
546
- * @callback LeUtils~__findIndexValueCallback
547
- * @param {*} value
548
- * @param {*} index
549
- * @returns {boolean|undefined}
550
- */
551
551
  /**
552
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
553
  *
554
554
  * @param {*[]|object|Function} elements
555
- * @param {LeUtils~__findIndexValueCallback} callback
555
+ * @param {(value:*, index:*) => boolean|void} callback
556
556
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
557
557
  * @returns {{index:*, value:*}|null}
558
558
  */
559
559
  findIndexValue: function findIndexValue(elements, callback) {
560
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
560
561
  var result = null;
561
562
  LeUtils.each(elements, function (value, index) {
562
563
  if (callback.call(elements[index], elements[index], index)) {
@@ -566,14 +567,14 @@ var LeUtils = {
566
567
  };
567
568
  return false;
568
569
  }
569
- });
570
+ }, optionalSkipHasOwnPropertyCheck);
570
571
  return result;
571
572
  },
572
573
  /**
573
574
  * Finds the first element in the given array or object that returns true from the callback, and returns the index.
574
575
  *
575
576
  * @param {*[]|object|Function} elements
576
- * @param {LeUtils~__findIndexValueCallback} callback
577
+ * @param {(value:*, index:*) => boolean|void} callback
577
578
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
578
579
  * @returns {*|null}
579
580
  */
@@ -586,7 +587,7 @@ var LeUtils = {
586
587
  * Finds the first element in the given array or object that returns true from the callback, and returns the value.
587
588
  *
588
589
  * @param {*[]|object|Function} elements
589
- * @param {LeUtils~__findIndexValueCallback} callback
590
+ * @param {(value:*, index:*) => boolean|void} callback
590
591
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
591
592
  * @returns {*|null}
592
593
  */
@@ -596,246 +597,525 @@ var LeUtils = {
596
597
  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
598
  },
598
599
  /**
599
- * @callback LeUtils~__eachCallback
600
- * @param {*} value
600
+ * Returns the value at the given index in the given elements.
601
+ *
602
+ * @param {*} elements
601
603
  * @param {*} index
602
- * @returns {boolean|undefined}
604
+ * @param {boolean} [optionalSkipHasOwnPropertyCheck]
605
+ * @returns {*}
603
606
  */
607
+ getValueAtIndex: function getValueAtIndex(elements, index) {
608
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
609
+ if (elements === null || typeof elements === 'undefined') {
610
+ return undefined;
611
+ }
612
+ if (Array.isArray(elements)) {
613
+ return elements[index];
614
+ }
615
+ if (_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object) {
616
+ if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, index)) {
617
+ return elements[index];
618
+ }
619
+ return undefined;
620
+ }
621
+ if (elements instanceof Map) {
622
+ return elements.get(index);
623
+ }
624
+ if (elements instanceof Set) {
625
+ return index;
626
+ }
627
+ if (ArrayBuffer.isView(elements) && !(elements instanceof DataView)) {
628
+ return elements[index];
629
+ }
630
+ if (typeof elements === 'string') {
631
+ return elements.charAt(index);
632
+ }
633
+ if (typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function') {
634
+ var i = 0;
635
+ var _iterator = _createForOfIteratorHelper(elements),
636
+ _step;
637
+ try {
638
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
639
+ var value = _step.value;
640
+ if (i === index) {
641
+ return value;
642
+ }
643
+ i++;
644
+ }
645
+ } catch (err) {
646
+ _iterator.e(err);
647
+ } finally {
648
+ _iterator.f();
649
+ }
650
+ return undefined;
651
+ }
652
+ if (typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function') {
653
+ var result = undefined;
654
+ var shouldContinue = true;
655
+ elements.forEach(function (value, i) {
656
+ if (shouldContinue) {
657
+ if (i === index) {
658
+ result = value;
659
+ shouldContinue = false;
660
+ }
661
+ }
662
+ });
663
+ return result;
664
+ }
665
+ if (_typeof(elements) === 'object' || typeof elements === 'function') {
666
+ if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, index)) {
667
+ return elements[index];
668
+ }
669
+ return undefined;
670
+ }
671
+ return undefined;
672
+ },
604
673
  /**
605
- * Loops through each element in the given array or object, and calls the callback for each element.
674
+ * Checks if the given elements can be iterated over using LeUtils.each().
606
675
  *
607
- * @param {*[]|object|Function} elements
608
- * @param {LeUtils~__eachCallback} callback
676
+ * @param {*} elements
677
+ * @returns {boolean}
678
+ */
679
+ supportsEach: function supportsEach(elements) {
680
+ if (elements === null || typeof elements === 'undefined') {
681
+ return false;
682
+ }
683
+ return !!(Array.isArray(elements) || _typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object || typeof elements === 'string' || typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function' || typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function' || _typeof(elements) === 'object' || typeof elements === 'function');
684
+ },
685
+ /**
686
+ * Returns an iterator that iterates over each element in the given array or object, yielding an array with the value and the index/key.
687
+ *
688
+ * @param {*} elements
609
689
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
610
- * @returns {*[]|object|Function}
690
+ * @returns {Generator<*, void, *>}
611
691
  */
612
- each: function each(elements, callback) {
613
- var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
614
- if (elements !== null && typeof elements !== 'undefined') {
615
- if (Array.isArray(elements)) {
616
- for (var index = 0; index < elements.length; index++) {
617
- if (callback.call(elements[index], elements[index], index) === false) {
692
+ eachIterator: function eachIterator(elements) {
693
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
694
+ return /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
695
+ var i, _i, _iterator2, _step2, _step2$value, _i2, value, _iterator3, _step3, _value, _i3, _i4, _iterator4, _step4, _value2, buffer, _i5, _buffer, entry, _i6, _t, _t2, _t3, _t4, _t5, _t6, _t7;
696
+ return _regeneratorRuntime.wrap(function (_context) {
697
+ while (1) switch (_context.prev = _context.next) {
698
+ case 0:
699
+ if (!(elements === null || typeof elements === 'undefined')) {
700
+ _context.next = 1;
701
+ break;
702
+ }
703
+ return _context.abrupt("return");
704
+ case 1:
705
+ if (!Array.isArray(elements)) {
706
+ _context.next = 5;
707
+ break;
708
+ }
709
+ i = 0;
710
+ case 2:
711
+ if (!(i < elements.length)) {
712
+ _context.next = 4;
713
+ break;
714
+ }
715
+ _context.next = 3;
716
+ return [elements[i], i];
717
+ case 3:
718
+ i++;
719
+ _context.next = 2;
618
720
  break;
619
- }
620
- }
621
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
622
- for (var _index in elements) {
623
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index)) {
624
- if (callback.call(elements[_index], elements[_index], _index) === false) {
721
+ case 4:
722
+ return _context.abrupt("return");
723
+ case 5:
724
+ if (!(_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object)) {
725
+ _context.next = 9;
625
726
  break;
626
727
  }
627
- }
728
+ _t = _regeneratorRuntime.keys(elements);
729
+ case 6:
730
+ if ((_t2 = _t()).done) {
731
+ _context.next = 8;
732
+ break;
733
+ }
734
+ _i = _t2.value;
735
+ if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _i))) {
736
+ _context.next = 7;
737
+ break;
738
+ }
739
+ _context.next = 7;
740
+ return [elements[_i], _i];
741
+ case 7:
742
+ _context.next = 6;
743
+ break;
744
+ case 8:
745
+ return _context.abrupt("return");
746
+ case 9:
747
+ if (!(elements instanceof Map)) {
748
+ _context.next = 17;
749
+ break;
750
+ }
751
+ _iterator2 = _createForOfIteratorHelper(elements);
752
+ _context.prev = 10;
753
+ _iterator2.s();
754
+ case 11:
755
+ if ((_step2 = _iterator2.n()).done) {
756
+ _context.next = 13;
757
+ break;
758
+ }
759
+ _step2$value = _slicedToArray(_step2.value, 2), _i2 = _step2$value[0], value = _step2$value[1];
760
+ _context.next = 12;
761
+ return [value, _i2];
762
+ case 12:
763
+ _context.next = 11;
764
+ break;
765
+ case 13:
766
+ _context.next = 15;
767
+ break;
768
+ case 14:
769
+ _context.prev = 14;
770
+ _t3 = _context["catch"](10);
771
+ _iterator2.e(_t3);
772
+ case 15:
773
+ _context.prev = 15;
774
+ _iterator2.f();
775
+ return _context.finish(15);
776
+ case 16:
777
+ return _context.abrupt("return");
778
+ case 17:
779
+ if (!(elements instanceof Set)) {
780
+ _context.next = 25;
781
+ break;
782
+ }
783
+ _iterator3 = _createForOfIteratorHelper(elements);
784
+ _context.prev = 18;
785
+ _iterator3.s();
786
+ case 19:
787
+ if ((_step3 = _iterator3.n()).done) {
788
+ _context.next = 21;
789
+ break;
790
+ }
791
+ _value = _step3.value;
792
+ _context.next = 20;
793
+ return [_value, _value];
794
+ case 20:
795
+ _context.next = 19;
796
+ break;
797
+ case 21:
798
+ _context.next = 23;
799
+ break;
800
+ case 22:
801
+ _context.prev = 22;
802
+ _t4 = _context["catch"](18);
803
+ _iterator3.e(_t4);
804
+ case 23:
805
+ _context.prev = 23;
806
+ _iterator3.f();
807
+ return _context.finish(23);
808
+ case 24:
809
+ return _context.abrupt("return");
810
+ case 25:
811
+ if (!(typeof elements === 'string')) {
812
+ _context.next = 29;
813
+ break;
814
+ }
815
+ _i3 = 0;
816
+ case 26:
817
+ if (!(_i3 < elements.length)) {
818
+ _context.next = 28;
819
+ break;
820
+ }
821
+ _context.next = 27;
822
+ return [elements.charAt(_i3), _i3];
823
+ case 27:
824
+ _i3++;
825
+ _context.next = 26;
826
+ break;
827
+ case 28:
828
+ return _context.abrupt("return");
829
+ case 29:
830
+ if (!(typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function')) {
831
+ _context.next = 38;
832
+ break;
833
+ }
834
+ _i4 = 0;
835
+ _iterator4 = _createForOfIteratorHelper(elements);
836
+ _context.prev = 30;
837
+ _iterator4.s();
838
+ case 31:
839
+ if ((_step4 = _iterator4.n()).done) {
840
+ _context.next = 34;
841
+ break;
842
+ }
843
+ _value2 = _step4.value;
844
+ _context.next = 32;
845
+ return [_value2, _i4];
846
+ case 32:
847
+ _i4++;
848
+ case 33:
849
+ _context.next = 31;
850
+ break;
851
+ case 34:
852
+ _context.next = 36;
853
+ break;
854
+ case 35:
855
+ _context.prev = 35;
856
+ _t5 = _context["catch"](30);
857
+ _iterator4.e(_t5);
858
+ case 36:
859
+ _context.prev = 36;
860
+ _iterator4.f();
861
+ return _context.finish(36);
862
+ case 37:
863
+ return _context.abrupt("return");
864
+ case 38:
865
+ if (!(typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function')) {
866
+ _context.next = 42;
867
+ break;
868
+ }
869
+ buffer = [];
870
+ elements.forEach(function (value, i) {
871
+ buffer.push([value, i]);
872
+ });
873
+ _i5 = 0, _buffer = buffer;
874
+ case 39:
875
+ if (!(_i5 < _buffer.length)) {
876
+ _context.next = 41;
877
+ break;
878
+ }
879
+ entry = _buffer[_i5];
880
+ _context.next = 40;
881
+ return entry;
882
+ case 40:
883
+ _i5++;
884
+ _context.next = 39;
885
+ break;
886
+ case 41:
887
+ return _context.abrupt("return");
888
+ case 42:
889
+ if (!(_typeof(elements) === 'object' || typeof elements === 'function')) {
890
+ _context.next = 46;
891
+ break;
892
+ }
893
+ _t6 = _regeneratorRuntime.keys(elements);
894
+ case 43:
895
+ if ((_t7 = _t6()).done) {
896
+ _context.next = 45;
897
+ break;
898
+ }
899
+ _i6 = _t7.value;
900
+ if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _i6))) {
901
+ _context.next = 44;
902
+ break;
903
+ }
904
+ _context.next = 44;
905
+ return [elements[_i6], _i6];
906
+ case 44:
907
+ _context.next = 43;
908
+ break;
909
+ case 45:
910
+ return _context.abrupt("return");
911
+ case 46:
912
+ console.warn('Executed LeUtils.eachIterator() on an invalid type: [' + _typeof(elements) + ']', elements);
913
+ case 47:
914
+ case "end":
915
+ return _context.stop();
916
+ }
917
+ }, _callee, null, [[10, 14, 15, 16], [18, 22, 23, 24], [30, 35, 36, 37]]);
918
+ })();
919
+ },
920
+ /**
921
+ * Loops through each element in the given array or object, and calls the callback for each element.
922
+ *
923
+ * @param {*} elements
924
+ * @param {(value:*, index?:*) => boolean|void} callback
925
+ * @param {boolean} [optionalSkipHasOwnPropertyCheck]
926
+ * @returns {*}
927
+ */
928
+ each: function each(elements, callback) {
929
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
930
+ var _iterator5 = _createForOfIteratorHelper(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck)),
931
+ _step5;
932
+ try {
933
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
934
+ var _step5$value = _slicedToArray(_step5.value, 2),
935
+ value = _step5$value[0],
936
+ key = _step5$value[1];
937
+ if (callback.call(value, value, key) === false) {
938
+ break;
628
939
  }
629
- } else {
630
- console.warn('Executed LeUtils.each() on an invalid type: [' + _typeof(elements) + ']', elements);
631
940
  }
941
+ } catch (err) {
942
+ _iterator5.e(err);
943
+ } finally {
944
+ _iterator5.f();
632
945
  }
633
946
  return elements;
634
947
  },
635
948
  /**
636
949
  * Like LeUtils.each(), except that it expects an async callback.
637
950
  *
638
- * @param {*[]|object|function} elements
639
- * @param {LeUtils~__eachCallback} asyncCallback
951
+ * @param {*} elements
952
+ * @param {(value:*, index?:*) => Promise<boolean|undefined>} asyncCallback
640
953
  * @param {number} [optionalParallelCount]
641
954
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
642
- * @returns {*[]|object|function}
955
+ * @returns {Promise<*>}
643
956
  */
644
957
  eachAsync: function () {
958
+ /**
959
+ * Instead of waiting for every promise individually, this function will queue up multiple promises at once, then wait for any of them to finish, before adding more, until it has looped through all elements.
960
+ * Then, at the end, it will wait for the remaining promises to finish.
961
+ */
645
962
  var eachAsyncParallel = /*#__PURE__*/function () {
646
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(elements, asyncCallback, optionalParallelCount, optionalSkipHasOwnPropertyCheck) {
647
- var promises, doBreak;
648
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
963
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(elements, asyncCallback, optionalParallelCount, optionalSkipHasOwnPropertyCheck) {
964
+ var runningPromises, doBreak;
965
+ return _regeneratorRuntime.wrap(function (_context4) {
649
966
  while (1) switch (_context4.prev = _context4.next) {
650
967
  case 0:
651
- promises = [];
968
+ runningPromises = new Set();
652
969
  doBreak = false;
653
- _context4.next = 4;
970
+ _context4.next = 1;
654
971
  return LeUtils.eachAsync(elements, /*#__PURE__*/function () {
655
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(element, index) {
656
- var _loop, promise;
657
- return _regeneratorRuntime.wrap(function _callee2$(_context3) {
972
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(value, index) {
973
+ var promise;
974
+ return _regeneratorRuntime.wrap(function (_context3) {
658
975
  while (1) switch (_context3.prev = _context3.next) {
659
976
  case 0:
660
- _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
661
- var newPromises;
662
- return _regeneratorRuntime.wrap(function _loop$(_context2) {
663
- while (1) switch (_context2.prev = _context2.next) {
664
- case 0:
665
- newPromises = [];
666
- LeUtils.each(promises, function (promise) {
667
- if (!promise.__lowentry_utils__promise_is_done__) {
668
- newPromises.push(promise);
669
- }
670
- });
671
- promises = newPromises;
672
- if (!(promises.length > optionalParallelCount)) {
673
- _context2.next = 6;
674
- break;
675
- }
676
- _context2.next = 6;
677
- return Promise.any(promises);
678
- case 6:
679
- case "end":
680
- return _context2.stop();
681
- }
682
- }, _loop);
683
- });
977
+ if (!doBreak) {
978
+ _context3.next = 1;
979
+ break;
980
+ }
981
+ return _context3.abrupt("return", false);
684
982
  case 1:
685
- if (!(promises.length > optionalParallelCount)) {
686
- _context3.next = 5;
983
+ if (!(runningPromises.size >= optionalParallelCount)) {
984
+ _context3.next = 4;
687
985
  break;
688
986
  }
689
- return _context3.delegateYield(_loop(), "t0", 3);
690
- case 3:
691
- _context3.next = 1;
692
- break;
693
- case 5:
987
+ _context3.next = 2;
988
+ return Promise.race(runningPromises);
989
+ case 2:
694
990
  if (!doBreak) {
695
- _context3.next = 7;
991
+ _context3.next = 3;
696
992
  break;
697
993
  }
698
994
  return _context3.abrupt("return", false);
699
- case 7:
700
- promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
701
- return _regeneratorRuntime.wrap(function _callee$(_context) {
702
- while (1) switch (_context.prev = _context.next) {
995
+ case 3:
996
+ _context3.next = 1;
997
+ break;
998
+ case 4:
999
+ // process this element, by creating a promise, and adding it to the queue
1000
+ promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1001
+ var _t8;
1002
+ return _regeneratorRuntime.wrap(function (_context2) {
1003
+ while (1) switch (_context2.prev = _context2.next) {
703
1004
  case 0:
704
- _context.next = 2;
705
- return asyncCallback.call(element, element, index);
706
- case 2:
707
- _context.t0 = _context.sent;
708
- if (!(_context.t0 === false)) {
709
- _context.next = 5;
1005
+ _context2.next = 1;
1006
+ return asyncCallback.call(value, value, index);
1007
+ case 1:
1008
+ _t8 = _context2.sent;
1009
+ if (!(_t8 === false)) {
1010
+ _context2.next = 2;
710
1011
  break;
711
1012
  }
712
1013
  doBreak = true;
713
- case 5:
714
- promise.__lowentry_utils__promise_is_done__ = true;
715
- case 6:
1014
+ case 2:
716
1015
  case "end":
717
- return _context.stop();
1016
+ return _context2.stop();
718
1017
  }
719
- }, _callee);
1018
+ }, _callee2);
720
1019
  }))();
721
- promises.push(promise);
722
- case 9:
1020
+ runningPromises.add(promise);
1021
+ promise["finally"](function () {
1022
+ runningPromises["delete"](promise);
1023
+ });
1024
+ case 5:
723
1025
  case "end":
724
1026
  return _context3.stop();
725
1027
  }
726
- }, _callee2);
1028
+ }, _callee3);
727
1029
  }));
728
1030
  return function (_x5, _x6) {
729
1031
  return _ref3.apply(this, arguments);
730
1032
  };
731
- }(), optionalSkipHasOwnPropertyCheck);
732
- case 4:
733
- _context4.next = 6;
734
- return Promise.all(promises);
735
- case 6:
1033
+ }(), 1, optionalSkipHasOwnPropertyCheck);
1034
+ case 1:
1035
+ _context4.next = 2;
1036
+ return Promise.all(runningPromises);
1037
+ case 2:
736
1038
  return _context4.abrupt("return", elements);
737
- case 7:
1039
+ case 3:
738
1040
  case "end":
739
1041
  return _context4.stop();
740
1042
  }
741
- }, _callee3);
1043
+ }, _callee4);
742
1044
  }));
743
1045
  return function eachAsyncParallel(_x, _x2, _x3, _x4) {
744
1046
  return _ref2.apply(this, arguments);
745
1047
  };
746
1048
  }();
747
1049
  return /*#__PURE__*/function () {
748
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(elements, asyncCallback) {
1050
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(elements, asyncCallback) {
749
1051
  var parallelCount,
750
1052
  optionalSkipHasOwnPropertyCheck,
751
- index,
752
- _index2,
753
- _args5 = arguments;
754
- return _regeneratorRuntime.wrap(function _callee4$(_context5) {
1053
+ _iterator6,
1054
+ _step6,
1055
+ _step6$value,
1056
+ value,
1057
+ key,
1058
+ _args5 = arguments,
1059
+ _t9,
1060
+ _t0;
1061
+ return _regeneratorRuntime.wrap(function (_context5) {
755
1062
  while (1) switch (_context5.prev = _context5.next) {
756
1063
  case 0:
757
1064
  parallelCount = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 1;
758
1065
  optionalSkipHasOwnPropertyCheck = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : false;
759
1066
  if (!(elements !== null && typeof elements !== 'undefined')) {
760
- _context5.next = 36;
1067
+ _context5.next = 10;
761
1068
  break;
762
1069
  }
763
1070
  parallelCount = INT_LAX(parallelCount);
764
1071
  if (!(parallelCount > 1)) {
765
- _context5.next = 8;
1072
+ _context5.next = 2;
766
1073
  break;
767
1074
  }
768
- _context5.next = 7;
1075
+ _context5.next = 1;
769
1076
  return eachAsyncParallel(elements, asyncCallback, parallelCount, optionalSkipHasOwnPropertyCheck);
770
- case 7:
1077
+ case 1:
771
1078
  return _context5.abrupt("return", _context5.sent);
772
- case 8:
773
- if (!Array.isArray(elements)) {
774
- _context5.next = 21;
775
- break;
776
- }
777
- index = 0;
778
- case 10:
779
- if (!(index < elements.length)) {
780
- _context5.next = 19;
781
- break;
782
- }
783
- _context5.next = 13;
784
- return asyncCallback.call(elements[index], elements[index], index);
785
- case 13:
786
- _context5.t0 = _context5.sent;
787
- if (!(_context5.t0 === false)) {
788
- _context5.next = 16;
789
- break;
790
- }
791
- return _context5.abrupt("break", 19);
792
- case 16:
793
- index++;
794
- _context5.next = 10;
795
- break;
796
- case 19:
797
- _context5.next = 36;
798
- break;
799
- case 21:
800
- if (!(_typeof(elements) === 'object' || typeof elements === 'function')) {
801
- _context5.next = 35;
802
- break;
803
- }
804
- _context5.t1 = _regeneratorRuntime.keys(elements);
805
- case 23:
806
- if ((_context5.t2 = _context5.t1()).done) {
807
- _context5.next = 33;
808
- break;
809
- }
810
- _index2 = _context5.t2.value;
811
- if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index2))) {
812
- _context5.next = 31;
1079
+ case 2:
1080
+ _iterator6 = _createForOfIteratorHelper(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck));
1081
+ _context5.prev = 3;
1082
+ _iterator6.s();
1083
+ case 4:
1084
+ if ((_step6 = _iterator6.n()).done) {
1085
+ _context5.next = 7;
813
1086
  break;
814
1087
  }
815
- _context5.next = 28;
816
- return asyncCallback.call(elements[_index2], elements[_index2], _index2);
817
- case 28:
818
- _context5.t3 = _context5.sent;
819
- if (!(_context5.t3 === false)) {
820
- _context5.next = 31;
1088
+ _step6$value = _slicedToArray(_step6.value, 2), value = _step6$value[0], key = _step6$value[1];
1089
+ _context5.next = 5;
1090
+ return asyncCallback.call(value, value, key);
1091
+ case 5:
1092
+ _t9 = _context5.sent;
1093
+ if (!(_t9 === false)) {
1094
+ _context5.next = 6;
821
1095
  break;
822
1096
  }
823
- return _context5.abrupt("break", 33);
824
- case 31:
825
- _context5.next = 23;
1097
+ return _context5.abrupt("continue", 7);
1098
+ case 6:
1099
+ _context5.next = 4;
826
1100
  break;
827
- case 33:
828
- _context5.next = 36;
1101
+ case 7:
1102
+ _context5.next = 9;
829
1103
  break;
830
- case 35:
831
- console.warn('Executed LeUtils.eachAsync() on an invalid type: [' + _typeof(elements) + ']', elements);
832
- case 36:
1104
+ case 8:
1105
+ _context5.prev = 8;
1106
+ _t0 = _context5["catch"](3);
1107
+ _iterator6.e(_t0);
1108
+ case 9:
1109
+ _context5.prev = 9;
1110
+ _iterator6.f();
1111
+ return _context5.finish(9);
1112
+ case 10:
833
1113
  return _context5.abrupt("return", elements);
834
- case 37:
1114
+ case 11:
835
1115
  case "end":
836
1116
  return _context5.stop();
837
1117
  }
838
- }, _callee4);
1118
+ }, _callee5, null, [[3, 8, 9, 10]]);
839
1119
  }));
840
1120
  return function (_x7, _x8) {
841
1121
  return _ref5.apply(this, arguments);
@@ -843,146 +1123,137 @@ var LeUtils = {
843
1123
  }();
844
1124
  }(),
845
1125
  /**
846
- * @callback LeUtils~__filterCallback
847
- * @param {*} value
848
- * @param {*} index
849
- * @returns {boolean|undefined}
1126
+ * Returns an empty simplified collection (array, object, or Map), based on the given elements.
1127
+ *
1128
+ * Usage:
1129
+ *
1130
+ * ```js
1131
+ * const [success, collection, add] = LeUtils.getEmptySimplifiedCollection(elements);
1132
+ * ```
1133
+ *
1134
+ * @param {*} elements
1135
+ * @returns {[boolean, *[]|object|Map, (value:*,index:*)=>void]}
850
1136
  */
1137
+ getEmptySimplifiedCollection: function getEmptySimplifiedCollection(elements) {
1138
+ if (elements === null || typeof elements === 'undefined') {
1139
+ return [false, [], function (value, index) {}];
1140
+ }
1141
+ var collection = null;
1142
+ var add = null;
1143
+ if (Array.isArray(elements)) {
1144
+ collection = [];
1145
+ add = function add(value, index) {
1146
+ collection.push(value);
1147
+ };
1148
+ } else if (_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object) {
1149
+ collection = {};
1150
+ add = function add(value, index) {
1151
+ collection[index] = value;
1152
+ };
1153
+ } else if (elements instanceof Map) {
1154
+ collection = new Map();
1155
+ add = function add(value, index) {
1156
+ collection.set(index, value);
1157
+ };
1158
+ } else if (typeof elements === 'string' || typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function' || typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function') {
1159
+ collection = [];
1160
+ add = function add(value, index) {
1161
+ collection.push(value);
1162
+ };
1163
+ } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
1164
+ collection = {};
1165
+ add = function add(value, index) {
1166
+ collection[index] = value;
1167
+ };
1168
+ } else {
1169
+ console.warn('Executed LeUtils.getEmptySimplifiedCollection() on an invalid type: [' + _typeof(elements) + ']', elements);
1170
+ return [false, [], function (value, index) {}];
1171
+ }
1172
+ return [true, collection, add];
1173
+ },
851
1174
  /**
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.
1175
+ * Loops through the given elements, and returns a new collection, with only the elements that returned true (or a value equals to true) from the callback.
853
1176
  * 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).
854
1177
  *
855
- * @param {*[]|object|Function} elements
856
- * @param {LeUtils~__filterCallback} [callback]
1178
+ * @param {*} elements
1179
+ * @param {(value:*, index:*) => boolean|undefined} [callback]
857
1180
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
858
- * @returns {*[]|object|Function}
1181
+ * @returns {*}
859
1182
  */
860
1183
  filter: function filter(elements, callback) {
861
1184
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
862
- if (elements !== null && typeof elements !== 'undefined') {
863
- if (Array.isArray(elements)) {
864
- var result = [];
865
- for (var index = 0; index < elements.length; index++) {
866
- if (!callback && elements[index] || callback && callback.call(elements[index], elements[index], index)) {
867
- result.push(elements[index]);
868
- }
869
- }
870
- return result;
871
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
872
- var _result = {};
873
- for (var _index3 in elements) {
874
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index3)) {
875
- if (!callback && elements[_index3] || callback && callback.call(elements[_index3], elements[_index3], _index3)) {
876
- _result[_index3] = elements[_index3];
877
- }
878
- }
1185
+ var _LeUtils$getEmptySimp = LeUtils.getEmptySimplifiedCollection(elements),
1186
+ _LeUtils$getEmptySimp2 = _slicedToArray(_LeUtils$getEmptySimp, 3),
1187
+ success = _LeUtils$getEmptySimp2[0],
1188
+ collection = _LeUtils$getEmptySimp2[1],
1189
+ add = _LeUtils$getEmptySimp2[2];
1190
+ if (!success) {
1191
+ return elements;
1192
+ }
1193
+ LeUtils.each(elements, function (value, index) {
1194
+ if (!callback) {
1195
+ if (value) {
1196
+ add(value, index);
879
1197
  }
880
- return _result;
881
- } else {
882
- console.warn('Executed LeUtils.filter() on an invalid type: [' + _typeof(elements) + ']', elements);
1198
+ } else if (callback.call(value, value, index)) {
1199
+ add(value, index);
883
1200
  }
884
- }
885
- return elements;
1201
+ }, optionalSkipHasOwnPropertyCheck);
1202
+ return collection;
886
1203
  },
887
1204
  /**
888
- * @callback LeUtils~__mapCallback
889
- * @param {*} value
890
- * @param {*} index
891
- * @returns {*}
892
- */
893
- /**
894
- * Loops through the given elements, and returns a new array or object, with the elements that were returned from the callback.
1205
+ * Loops through the given elements, and returns a new collection, with the elements that were returned from the callback.
895
1206
  *
896
- * @param {*[]|object|Function} elements
897
- * @param {LeUtils~__mapCallback} [callback]
1207
+ * @param {*} elements
1208
+ * @param {(value:*, index:*) => *} [callback]
898
1209
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
899
- * @returns {*[]|object|Function}
1210
+ * @returns {*}
900
1211
  */
901
1212
  map: function map(elements, callback) {
902
1213
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
903
- if (elements !== null && typeof elements !== 'undefined') {
904
- if (Array.isArray(elements)) {
905
- var result = [];
906
- for (var index = 0; index < elements.length; index++) {
907
- if (!callback) {
908
- result[index] = elements[index];
909
- } else {
910
- result[index] = callback.call(elements[index], elements[index], index);
911
- }
912
- }
913
- return result;
914
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
915
- var _result2 = {};
916
- for (var _index4 in elements) {
917
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index4)) {
918
- if (!callback) {
919
- _result2[_index4] = elements[_index4];
920
- } else {
921
- _result2[_index4] = callback.call(elements[_index4], elements[_index4], _index4);
922
- }
923
- }
924
- }
925
- return _result2;
1214
+ var _LeUtils$getEmptySimp3 = LeUtils.getEmptySimplifiedCollection(elements),
1215
+ _LeUtils$getEmptySimp4 = _slicedToArray(_LeUtils$getEmptySimp3, 3),
1216
+ success = _LeUtils$getEmptySimp4[0],
1217
+ collection = _LeUtils$getEmptySimp4[1],
1218
+ add = _LeUtils$getEmptySimp4[2];
1219
+ if (!success) {
1220
+ return elements;
1221
+ }
1222
+ LeUtils.each(elements, function (value, index) {
1223
+ if (!callback) {
1224
+ add(value, index);
926
1225
  } else {
927
- console.warn('Executed LeUtils.map() on an invalid type: [' + _typeof(elements) + ']', elements);
1226
+ add(callback.call(value, value, index), index);
928
1227
  }
929
- }
930
- return elements;
1228
+ }, optionalSkipHasOwnPropertyCheck);
1229
+ return collection;
931
1230
  },
932
- /**
933
- * @callback LeUtils~__mapToArrayCallback
934
- * @param {*} value
935
- * @param {*} index
936
- * @returns {*}
937
- */
938
1231
  /**
939
1232
  * Loops through the given elements, and returns a new array, with the elements that were returned from the callback. Always returns an array.
940
1233
  *
941
- * @param {*[]|object|Function} elements
942
- * @param {LeUtils~__mapToArrayCallback} [callback]
1234
+ * @param {*} elements
1235
+ * @param {(value:*, index:*) => *} [callback]
943
1236
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
944
1237
  * @returns {*[]}
945
1238
  */
946
1239
  mapToArray: function mapToArray(elements, callback) {
947
1240
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
948
1241
  var result = [];
949
- if (elements !== null && typeof elements !== 'undefined') {
950
- if (Array.isArray(elements)) {
951
- for (var index = 0; index < elements.length; index++) {
952
- if (!callback) {
953
- result.push(elements[index]);
954
- } else {
955
- result.push(callback.call(elements[index], elements[index], index));
956
- }
957
- }
958
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
959
- for (var _index5 in elements) {
960
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index5)) {
961
- if (!callback) {
962
- result.push(elements[_index5]);
963
- } else {
964
- result.push(callback.call(elements[_index5], elements[_index5], _index5));
965
- }
966
- }
967
- }
1242
+ LeUtils.each(elements, function (value, index) {
1243
+ if (!callback) {
1244
+ result.push(value);
968
1245
  } else {
969
- console.warn('Executed LeUtils.mapToArray() on an invalid type: [' + _typeof(elements) + ']', elements);
1246
+ result.push(callback.call(value, value, index));
970
1247
  }
971
- }
1248
+ }, optionalSkipHasOwnPropertyCheck);
972
1249
  return result;
973
1250
  },
974
- /**
975
- * @callback LeUtils~__mapToArraySortedCallback
976
- * @param {*} value
977
- * @param {*} index
978
- * @returns {*}
979
- */
980
1251
  /**
981
1252
  * 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.
982
1253
  *
983
- * @param {*[]|object|Function} elements
984
- * @param {LeUtils~__sortKeysComparatorCallback} comparator
985
- * @param {LeUtils~__mapToArraySortedCallback} [callback]
1254
+ * @param {*} elements
1255
+ * @param {(valueA:*, valueB:*) => number} comparator
1256
+ * @param {(value:*, index:*) => *} [callback]
986
1257
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
987
1258
  * @returns {*[]}
988
1259
  */
@@ -990,49 +1261,41 @@ var LeUtils = {
990
1261
  var optionalSkipHasOwnPropertyCheck = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
991
1262
  var keys = LeUtils.sortKeys(elements, comparator, optionalSkipHasOwnPropertyCheck);
992
1263
  var result = [];
993
- for (var i = 0; i < keys.length; 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]));
1264
+ var _iterator7 = _createForOfIteratorHelper(keys),
1265
+ _step7;
1266
+ try {
1267
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1268
+ var key = _step7.value;
1269
+ var value = LeUtils.getValueAtIndex(elements, key, optionalSkipHasOwnPropertyCheck);
1270
+ if (!callback) {
1271
+ result.push(value);
1272
+ } else {
1273
+ result.push(callback.call(value, value, key));
1274
+ }
998
1275
  }
1276
+ } catch (err) {
1277
+ _iterator7.e(err);
1278
+ } finally {
1279
+ _iterator7.f();
999
1280
  }
1000
1281
  return result;
1001
1282
  },
1002
- /**
1003
- * @callback LeUtils~__sortKeysComparatorCallback
1004
- * @param {*} elementA
1005
- * @param {*} elementB
1006
- * @returns {number}
1007
- */
1008
1283
  /**
1009
1284
  * 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.
1010
1285
  *
1011
- * @param {*[]|object|Function} elements
1012
- * @param {LeUtils~__sortKeysComparatorCallback} comparator
1286
+ * @param {*} elements
1287
+ * @param {(valueA:*, valueB:*) => number} comparator
1013
1288
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
1014
1289
  * @returns {*[]}
1015
1290
  */
1016
1291
  sortKeys: function sortKeys(elements, comparator) {
1017
1292
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1018
1293
  var keys = [];
1019
- if (elements !== null && typeof elements !== 'undefined') {
1020
- if (Array.isArray(elements)) {
1021
- for (var index = 0; index < elements.length; index++) {
1022
- keys.push(index);
1023
- }
1024
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
1025
- for (var _index6 in elements) {
1026
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index6)) {
1027
- keys.push(_index6);
1028
- }
1029
- }
1030
- } else {
1031
- console.warn('Executed LeUtils.sortKeys() on an invalid type: [' + _typeof(elements) + ']', elements);
1032
- }
1033
- }
1294
+ LeUtils.each(elements, function (value, index) {
1295
+ keys.push(index);
1296
+ }, optionalSkipHasOwnPropertyCheck);
1034
1297
  keys.sort(function (a, b) {
1035
- return comparator(elements[a], elements[b]);
1298
+ return comparator(LeUtils.getValueAtIndex(elements, a, optionalSkipHasOwnPropertyCheck), LeUtils.getValueAtIndex(elements, b, optionalSkipHasOwnPropertyCheck));
1036
1299
  });
1037
1300
  return keys;
1038
1301
  },
@@ -1065,6 +1328,37 @@ var LeUtils = {
1065
1328
  return result;
1066
1329
  };
1067
1330
  }(),
1331
+ /**
1332
+ * Turns the given value(s) into a 1 dimensional array.
1333
+ *
1334
+ * Compared to LeUtils.flattenArray(), this function also supports objects, Maps, Sets, and other iterable objects.
1335
+ *
1336
+ * @param {*} elements
1337
+ * @param {boolean} [optionalSkipHasOwnPropertyCheck]
1338
+ * @returns {*[]}
1339
+ */
1340
+ flattenToArray: function () {
1341
+ var _flattenToArrayRecursive = function flattenToArrayRecursive(result, elements, optionalSkipHasOwnPropertyCheck) {
1342
+ if (!LeUtils.supportsEach(elements)) {
1343
+ result.push(elements);
1344
+ return;
1345
+ }
1346
+ LeUtils.each(elements, function (entry) {
1347
+ _flattenToArrayRecursive(result, entry, optionalSkipHasOwnPropertyCheck);
1348
+ }, optionalSkipHasOwnPropertyCheck);
1349
+ };
1350
+ return function (elements) {
1351
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1352
+ if (!LeUtils.supportsEach(elements)) {
1353
+ return [elements];
1354
+ }
1355
+ var result = [];
1356
+ LeUtils.each(elements, function (entry) {
1357
+ _flattenToArrayRecursive(result, entry, optionalSkipHasOwnPropertyCheck);
1358
+ }, optionalSkipHasOwnPropertyCheck);
1359
+ return result;
1360
+ };
1361
+ }(),
1068
1362
  /**
1069
1363
  * Compares two values. Primarily used for sorting.
1070
1364
  *
@@ -1093,12 +1387,22 @@ var LeUtils = {
1093
1387
  * @returns {number}
1094
1388
  */
1095
1389
  compareNumericStrings: function compareNumericStrings(a, b) {
1096
- a = STRING(a).trim();
1097
- b = STRING(b).trim();
1098
- if (a.length === b.length) {
1099
- return a < b ? -1 : a > b ? 1 : 0;
1390
+ var aParts = STRING(a).split('.');
1391
+ var bParts = STRING(b).split('.');
1392
+ for (var i = 0; i < Math.min(aParts.length, bParts.length); i++) {
1393
+ a = aParts[i].trim();
1394
+ b = bParts[i].trim();
1395
+ if (a.length !== b.length) {
1396
+ return a.length < b.length ? -1 : 1;
1397
+ }
1398
+ if (a !== b) {
1399
+ return a < b ? -1 : 1;
1400
+ }
1401
+ }
1402
+ if (aParts.length !== bParts.length) {
1403
+ return aParts.length < bParts.length ? -1 : 1;
1100
1404
  }
1101
- return a.length < b.length ? -1 : 1;
1405
+ return 0;
1102
1406
  },
1103
1407
  /**
1104
1408
  * Compares two strings generated by LeUtils.timestamp(). Primarily used for sorting.
@@ -1152,27 +1456,27 @@ var LeUtils = {
1152
1456
  * @returns {boolean}
1153
1457
  */
1154
1458
  isGeneratorFunction: function () {
1155
- var GeneratorFunction = _regeneratorRuntime.mark(function _callee5() {
1156
- return _regeneratorRuntime.wrap(function _callee5$(_context6) {
1459
+ var GeneratorFunction = _regeneratorRuntime.mark(function _callee6() {
1460
+ return _regeneratorRuntime.wrap(function (_context6) {
1157
1461
  while (1) switch (_context6.prev = _context6.next) {
1158
1462
  case 0:
1159
1463
  case "end":
1160
1464
  return _context6.stop();
1161
1465
  }
1162
- }, _callee5);
1466
+ }, _callee6);
1163
1467
  }).constructor;
1164
- var AsyncGeneratorFunction = _wrapAsyncGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
1165
- return _regeneratorRuntime.wrap(function _callee6$(_context7) {
1468
+ var AsyncGeneratorFunction = _wrapAsyncGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
1469
+ return _regeneratorRuntime.wrap(function (_context7) {
1166
1470
  while (1) switch (_context7.prev = _context7.next) {
1167
1471
  case 0:
1168
1472
  case "end":
1169
1473
  return _context7.stop();
1170
1474
  }
1171
- }, _callee6);
1475
+ }, _callee7);
1172
1476
  })).constructor;
1173
1477
  var RegularFunction = function () {}.constructor;
1174
- var PossibleGeneratorFunctionNames = Array.from(new Set(['GeneratorFunction', 'AsyncFunction', 'AsyncGeneratorFunction', GeneratorFunction.name, GeneratorFunction.displayName, AsyncGeneratorFunction.name, AsyncGeneratorFunction.displayName])).filter(function (element) {
1175
- return element && element !== RegularFunction.name && element !== RegularFunction.displayName;
1478
+ var PossibleGeneratorFunctionNames = Array.from(new Set(['GeneratorFunction', 'AsyncFunction', 'AsyncGeneratorFunction', GeneratorFunction.name, AsyncGeneratorFunction.name])).filter(function (element) {
1479
+ return element && element !== RegularFunction.name;
1176
1480
  });
1177
1481
  return function (func) {
1178
1482
  if (!func) {
@@ -1182,19 +1486,16 @@ var LeUtils = {
1182
1486
  if (!constructor) {
1183
1487
  return false;
1184
1488
  }
1489
+ // noinspection JSUnresolvedVariable
1185
1490
  return constructor.name && PossibleGeneratorFunctionNames.includes(constructor.name) || constructor.displayName && PossibleGeneratorFunctionNames.includes(constructor.displayName);
1186
1491
  };
1187
1492
  }(),
1188
- /**
1189
- * @callback LeUtils~__setTimeoutCallback
1190
- * @param {number} deltaTime
1191
- */
1192
1493
  /**
1193
1494
  * Executes the callback after the given number of milliseconds. Passes the elapsed time in seconds to the callback.
1194
1495
  *
1195
1496
  * To cancel the timeout, call remove() on the result of this function (example: "const timeoutHandler = LeUtils.setTimeout((deltaTime)=>{}, 1000); timeoutHandler.remove();")
1196
1497
  *
1197
- * @param {LeUtils~__setTimeoutCallback} callback ([number] deltaTime)
1498
+ * @param {(deltaTime:number) => *} callback
1198
1499
  * @param {number} ms
1199
1500
  * @returns {{remove:Function}}
1200
1501
  */
@@ -1206,6 +1507,7 @@ var LeUtils = {
1206
1507
  }
1207
1508
  ms = FLOAT_LAX(ms);
1208
1509
  var lastTime = performance.now();
1510
+ /** @type {number|null} */
1209
1511
  var handler = window.setTimeout(function () {
1210
1512
  var currentTime = performance.now();
1211
1513
  try {
@@ -1224,16 +1526,12 @@ var LeUtils = {
1224
1526
  }
1225
1527
  };
1226
1528
  },
1227
- /**
1228
- * @callback LeUtils~__setIntervalCallback
1229
- * @param {number} deltaTime
1230
- */
1231
1529
  /**
1232
1530
  * Executes the callback every given number of milliseconds. Passes the time difference in seconds between the last frame and now to it.
1233
1531
  *
1234
1532
  * To remove the interval, call remove() on the result of this function (example: "const intervalHandler = LeUtils.setInterval((deltaTime)=>{}, 1000); intervalHandler.remove();")
1235
1533
  *
1236
- * @param {LeUtils~__setIntervalCallback} callback ([number] deltaTime)
1534
+ * @param {(deltaTime:number) => *} callback
1237
1535
  * @param {number} [intervalMs]
1238
1536
  * @param {boolean} [fireImmediately]
1239
1537
  * @returns {{remove:Function}}
@@ -1255,6 +1553,7 @@ var LeUtils = {
1255
1553
  };
1256
1554
  }
1257
1555
  var lastTime = performance.now();
1556
+ /** @type {number|null} */
1258
1557
  var handler = window.setInterval(function () {
1259
1558
  var currentTime = performance.now();
1260
1559
  try {
@@ -1273,16 +1572,12 @@ var LeUtils = {
1273
1572
  }
1274
1573
  };
1275
1574
  },
1276
- /**
1277
- * @callback LeUtils~__setAnimationFrameTimeoutCallback
1278
- * @param {number} deltaTime
1279
- */
1280
1575
  /**
1281
1576
  * Executes the callback after the given number of frames. Passes the elapsed time in seconds to the callback.
1282
1577
  *
1283
1578
  * To cancel the timeout, call remove() on the result of this function (example: "const timeoutHandler = LeUtils.setAnimationFrameTimeout((deltaTime){}, 5); timeoutHandler.remove();")
1284
1579
  *
1285
- * @param {LeUtils~__setAnimationFrameTimeoutCallback} callback ([number] deltaTime)
1580
+ * @param {(deltaTime:number) => *} callback
1286
1581
  * @param {number} [frames]
1287
1582
  * @returns {{remove:Function}}
1288
1583
  */
@@ -1326,16 +1621,12 @@ var LeUtils = {
1326
1621
  }
1327
1622
  };
1328
1623
  },
1329
- /**
1330
- * @callback LeUtils~__setAnimationFrameIntervalCallback
1331
- * @param {number} deltaTime
1332
- */
1333
1624
  /**
1334
1625
  * Executes the callback every given number of frames. Passes the time difference in seconds between the last frame and now to it.
1335
1626
  *
1336
1627
  * To remove the interval, call remove() on the result of this function (example: "const intervalHandler = LeUtils.setAnimationFrameInterval((deltaTime)=>{}, 5); intervalHandler.remove();")
1337
1628
  *
1338
- * @param {LeUtils~__setAnimationFrameIntervalCallback} callback ([number] deltaTime)
1629
+ * @param {(deltaTime:number) => *} callback
1339
1630
  * @param {number} [intervalFrames]
1340
1631
  * @param {boolean} [fireImmediately]
1341
1632
  * @returns {{remove:Function}}
@@ -1393,13 +1684,13 @@ var LeUtils = {
1393
1684
  * Returns a promise, which will be resolved after the given number of milliseconds.
1394
1685
  *
1395
1686
  * @param {number} ms
1396
- * @returns {Promise}
1687
+ * @returns {Promise<number>}
1397
1688
  */
1398
1689
  promiseTimeout: function promiseTimeout(ms) {
1399
1690
  ms = FLOAT_LAX(ms);
1400
1691
  if (ms <= 0) {
1401
1692
  return new Promise(function (resolve) {
1402
- return resolve(undefined);
1693
+ return resolve(0);
1403
1694
  });
1404
1695
  }
1405
1696
  return new Promise(function (resolve) {
@@ -1410,13 +1701,13 @@ var LeUtils = {
1410
1701
  * Returns a promise, which will be resolved after the given number of frames.
1411
1702
  *
1412
1703
  * @param {number} frames
1413
- * @returns {Promise}
1704
+ * @returns {Promise<number>}
1414
1705
  */
1415
1706
  promiseAnimationFrameTimeout: function promiseAnimationFrameTimeout(frames) {
1416
1707
  frames = INT_LAX(frames);
1417
1708
  if (frames <= 0) {
1418
1709
  return new Promise(function (resolve) {
1419
- return resolve(undefined);
1710
+ return resolve(0);
1420
1711
  });
1421
1712
  }
1422
1713
  return new Promise(function (resolve) {
@@ -1427,11 +1718,11 @@ var LeUtils = {
1427
1718
  * Allows you to do a fetch, with built-in retry and abort functionality.
1428
1719
  *
1429
1720
  * @param {string} url
1430
- * @param {{[retries]:number|null, [delay]:number|((attempt:number)=>number)|null}|null} [options]
1721
+ * @param {{retries?:number|null, delay?:number|((attempt:number)=>number)|null}|object|null} [options]
1431
1722
  * @returns {{then:Function, catch:Function, finally:Function, remove:Function, isRemoved:Function}}
1432
1723
  */
1433
1724
  fetch: function (_fetch) {
1434
- function fetch(_x9, _x10) {
1725
+ function fetch(_x9, _x0) {
1435
1726
  return _fetch.apply(this, arguments);
1436
1727
  }
1437
1728
  fetch.toString = function () {
@@ -1446,83 +1737,83 @@ var LeUtils = {
1446
1737
  if (typeof window !== 'undefined' && typeof window.AbortController !== 'undefined') {
1447
1738
  controller = new AbortController();
1448
1739
  }
1449
- var promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
1740
+ var promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
1450
1741
  var _attemptFetch;
1451
- return _regeneratorRuntime.wrap(function _callee8$(_context9) {
1742
+ return _regeneratorRuntime.wrap(function (_context9) {
1452
1743
  while (1) switch (_context9.prev = _context9.next) {
1453
1744
  case 0:
1454
1745
  _attemptFetch = /*#__PURE__*/function () {
1455
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
1746
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
1456
1747
  var _controller;
1457
- var _controller2, response, _controller3;
1458
- return _regeneratorRuntime.wrap(function _callee7$(_context8) {
1748
+ var _controller2, response, _controller3, _t1;
1749
+ return _regeneratorRuntime.wrap(function (_context8) {
1459
1750
  while (1) switch (_context8.prev = _context8.next) {
1460
1751
  case 0:
1461
1752
  if (!(controllerAborted || (_controller = controller) !== null && _controller !== void 0 && (_controller = _controller.signal) !== null && _controller !== void 0 && _controller.aborted)) {
1462
- _context8.next = 2;
1753
+ _context8.next = 1;
1463
1754
  break;
1464
1755
  }
1465
1756
  throw new Error('Aborted');
1466
- case 2:
1467
- _context8.prev = 2;
1468
- _context8.next = 5;
1757
+ case 1:
1758
+ _context8.prev = 1;
1759
+ _context8.next = 2;
1469
1760
  return fetch(url, _objectSpread(_objectSpread({
1470
1761
  signal: (_controller2 = controller) === null || _controller2 === void 0 ? void 0 : _controller2.signal
1471
1762
  }, options !== null && options !== void 0 ? options : {}), {}, {
1472
1763
  retries: undefined,
1473
1764
  delay: undefined
1474
1765
  }));
1475
- case 5:
1766
+ case 2:
1476
1767
  response = _context8.sent;
1477
1768
  if (response.ok) {
1478
- _context8.next = 8;
1769
+ _context8.next = 3;
1479
1770
  break;
1480
1771
  }
1481
1772
  throw new Error('Network request failed: ' + response.status + ' ' + response.statusText);
1482
- case 8:
1773
+ case 3:
1483
1774
  return _context8.abrupt("return", response);
1484
- case 11:
1485
- _context8.prev = 11;
1486
- _context8.t0 = _context8["catch"](2);
1775
+ case 4:
1776
+ _context8.prev = 4;
1777
+ _t1 = _context8["catch"](1);
1487
1778
  if (!(controllerAborted || (_controller3 = controller) !== null && _controller3 !== void 0 && (_controller3 = _controller3.signal) !== null && _controller3 !== void 0 && _controller3.aborted)) {
1488
- _context8.next = 15;
1779
+ _context8.next = 5;
1489
1780
  break;
1490
1781
  }
1491
1782
  throw new Error('Aborted');
1492
- case 15:
1783
+ case 5:
1493
1784
  if (!(currentRetries >= retries)) {
1494
- _context8.next = 17;
1785
+ _context8.next = 6;
1495
1786
  break;
1496
1787
  }
1497
- throw _context8.t0;
1498
- case 17:
1788
+ throw _t1;
1789
+ case 6:
1499
1790
  currentRetries++;
1500
- _context8.next = 20;
1791
+ _context8.next = 7;
1501
1792
  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));
1502
- case 20:
1503
- _context8.next = 22;
1793
+ case 7:
1794
+ _context8.next = 8;
1504
1795
  return _attemptFetch();
1505
- case 22:
1796
+ case 8:
1506
1797
  return _context8.abrupt("return", _context8.sent);
1507
- case 23:
1798
+ case 9:
1508
1799
  case "end":
1509
1800
  return _context8.stop();
1510
1801
  }
1511
- }, _callee7, null, [[2, 11]]);
1802
+ }, _callee8, null, [[1, 4]]);
1512
1803
  }));
1513
1804
  return function attemptFetch() {
1514
1805
  return _ref7.apply(this, arguments);
1515
1806
  };
1516
1807
  }();
1517
- _context9.next = 3;
1808
+ _context9.next = 1;
1518
1809
  return _attemptFetch();
1519
- case 3:
1810
+ case 1:
1520
1811
  return _context9.abrupt("return", _context9.sent);
1521
- case 4:
1812
+ case 2:
1522
1813
  case "end":
1523
1814
  return _context9.stop();
1524
1815
  }
1525
- }, _callee8);
1816
+ }, _callee9);
1526
1817
  }))();
1527
1818
  var result = {};
1528
1819
  result.then = function () {
@@ -1558,82 +1849,82 @@ var LeUtils = {
1558
1849
  * Allows you to do a fetch, with built-in retry functionality. Caches on the requested URL, so that the same URL will not be fetched multiple times.
1559
1850
  *
1560
1851
  * @param {string} url
1561
- * @param {{[retries]:number|null, [delay]:number|((attempt:number)=>number)|null, [verify]:((data:*, response:*)=>void)|null}|null} [options]
1562
- * @param {((response:*) => *)|null} [responseFunction] A function that will be called with the response object, and should return the data to be cached.
1852
+ * @param {{retries?:number|null, delay?:number|((attempt:number)=>number)|null, [verify]:((data:*,response:*)=>void)|null}|null} [options]
1853
+ * @param {((response:*)=>*)|null} [responseFunction] A function that will be called with the response object, and should return the data to be cached.
1563
1854
  * @returns {Promise<*>}
1564
1855
  */
1565
1856
  cachedFetch: function () {
1566
1857
  var cache = new Map();
1567
1858
  return /*#__PURE__*/function () {
1568
- var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10(url, options, responseFunction) {
1859
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1(url, options, responseFunction) {
1569
1860
  var result, promise;
1570
- return _regeneratorRuntime.wrap(function _callee10$(_context11) {
1571
- while (1) switch (_context11.prev = _context11.next) {
1861
+ return _regeneratorRuntime.wrap(function (_context1) {
1862
+ while (1) switch (_context1.prev = _context1.next) {
1572
1863
  case 0:
1573
1864
  if (!cache.has(url)) {
1574
- _context11.next = 12;
1865
+ _context1.next = 5;
1575
1866
  break;
1576
1867
  }
1577
1868
  result = cache.get(url);
1578
1869
  if (!result.data) {
1579
- _context11.next = 4;
1870
+ _context1.next = 1;
1580
1871
  break;
1581
1872
  }
1582
- return _context11.abrupt("return", result.data);
1583
- case 4:
1873
+ return _context1.abrupt("return", result.data);
1874
+ case 1:
1584
1875
  if (!result.promise) {
1585
- _context11.next = 8;
1876
+ _context1.next = 3;
1586
1877
  break;
1587
1878
  }
1588
- _context11.next = 7;
1879
+ _context1.next = 2;
1589
1880
  return result.promise;
1590
- case 7:
1591
- return _context11.abrupt("return", _context11.sent);
1592
- case 8:
1881
+ case 2:
1882
+ return _context1.abrupt("return", _context1.sent);
1883
+ case 3:
1593
1884
  if (!result.error) {
1594
- _context11.next = 10;
1885
+ _context1.next = 4;
1595
1886
  break;
1596
1887
  }
1597
1888
  throw result.error;
1598
- case 10:
1889
+ case 4:
1599
1890
  console.warn('Failed to use the cachedFetch cache, for URL: ', url, ', it is in an unexpected state: ', result);
1600
- return _context11.abrupt("return", null);
1601
- case 12:
1891
+ return _context1.abrupt("return", null);
1892
+ case 5:
1602
1893
  promise = LeUtils.fetch(url, options).then(/*#__PURE__*/function () {
1603
- var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(response) {
1604
- var data;
1605
- return _regeneratorRuntime.wrap(function _callee9$(_context10) {
1606
- while (1) switch (_context10.prev = _context10.next) {
1894
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(response) {
1895
+ var data, _t10;
1896
+ return _regeneratorRuntime.wrap(function (_context0) {
1897
+ while (1) switch (_context0.prev = _context0.next) {
1607
1898
  case 0:
1608
1899
  if (!responseFunction) {
1609
- _context10.next = 6;
1900
+ _context0.next = 2;
1610
1901
  break;
1611
1902
  }
1612
- _context10.next = 3;
1903
+ _context0.next = 1;
1613
1904
  return responseFunction(response);
1614
- case 3:
1615
- _context10.t0 = _context10.sent;
1616
- _context10.next = 7;
1905
+ case 1:
1906
+ _t10 = _context0.sent;
1907
+ _context0.next = 3;
1617
1908
  break;
1618
- case 6:
1619
- _context10.t0 = response;
1620
- case 7:
1621
- data = _context10.t0;
1909
+ case 2:
1910
+ _t10 = response;
1911
+ case 3:
1912
+ data = _t10;
1622
1913
  if (!(typeof (options === null || options === void 0 ? void 0 : options.verify) === 'function')) {
1623
- _context10.next = 11;
1914
+ _context0.next = 4;
1624
1915
  break;
1625
1916
  }
1626
- _context10.next = 11;
1917
+ _context0.next = 4;
1627
1918
  return options.verify(data, response);
1628
- case 11:
1629
- return _context10.abrupt("return", data);
1630
- case 12:
1919
+ case 4:
1920
+ return _context0.abrupt("return", data);
1921
+ case 5:
1631
1922
  case "end":
1632
- return _context10.stop();
1923
+ return _context0.stop();
1633
1924
  }
1634
- }, _callee9);
1925
+ }, _callee0);
1635
1926
  }));
1636
- return function (_x14) {
1927
+ return function (_x12) {
1637
1928
  return _ref9.apply(this, arguments);
1638
1929
  };
1639
1930
  }()).then(function (data) {
@@ -1653,17 +1944,17 @@ var LeUtils = {
1653
1944
  promise: promise
1654
1945
  });
1655
1946
  }
1656
- _context11.next = 16;
1947
+ _context1.next = 6;
1657
1948
  return promise;
1658
- case 16:
1659
- return _context11.abrupt("return", _context11.sent);
1660
- case 17:
1949
+ case 6:
1950
+ return _context1.abrupt("return", _context1.sent);
1951
+ case 7:
1661
1952
  case "end":
1662
- return _context11.stop();
1953
+ return _context1.stop();
1663
1954
  }
1664
- }, _callee10);
1955
+ }, _callee1);
1665
1956
  }));
1666
- return function (_x11, _x12, _x13) {
1957
+ return function (_x1, _x10, _x11) {
1667
1958
  return _ref8.apply(this, arguments);
1668
1959
  };
1669
1960
  }();
@@ -1873,7 +2164,7 @@ var LeUtils = {
1873
2164
  * - foo-bar
1874
2165
  * - foo_bar
1875
2166
  *
1876
- * @param {string} names
2167
+ * @param {string[]} names
1877
2168
  * @returns {string[]}
1878
2169
  */
1879
2170
  generateNamePermutations: function generateNamePermutations() {
@@ -1916,17 +2207,17 @@ var LeUtils = {
1916
2207
  if (string === '') {
1917
2208
  return '1';
1918
2209
  }
1919
- for (var _i = string.length - 1; _i >= 0; _i--) {
1920
- var _c = string.charAt(_i);
2210
+ for (var _i7 = string.length - 1; _i7 >= 0; _i7--) {
2211
+ var _c = string.charAt(_i7);
1921
2212
  if (_c < '0' || _c > '9') {
1922
2213
  return '1';
1923
2214
  }
1924
2215
  if (_c < '9') {
1925
- _c++;
1926
- string = string.substring(0, _i) + _c + string.substring(_i + 1); // string[i] = (char + 1);
2216
+ _c = String.fromCharCode(_c.charCodeAt(0) + 1);
2217
+ string = string.substring(0, _i7) + _c + string.substring(_i7 + 1); // string[i] = (char + 1);
1927
2218
  break;
1928
2219
  }
1929
- string = string.substring(0, _i) + '0' + string.substring(_i + 1); // string[i] = '0';
2220
+ string = string.substring(0, _i7) + '0' + string.substring(_i7 + 1); // string[i] = '0';
1930
2221
  }
1931
2222
  if (string.charAt(0) === '0') {
1932
2223
  string = '1' + string;
@@ -2070,7 +2361,7 @@ var LeUtils = {
2070
2361
  getPercentage: function getPercentage(part, total) {
2071
2362
  part = FLOAT_LAX(part);
2072
2363
  total = FLOAT_LAX(total);
2073
- if (total <= 0) {
2364
+ if (total === 0) {
2074
2365
  return 100;
2075
2366
  }
2076
2367
  return Math.max(0, Math.min(100, part / total * 100));
@@ -2091,17 +2382,16 @@ var LeUtils = {
2091
2382
  var ctx = canvas.getContext('2d');
2092
2383
  var width = Math.floor(image.width);
2093
2384
  var height = Math.floor(image.height);
2094
- if (width <= 0 || height <= 0) {
2095
- canvas.width = 1;
2096
- canvas.height = 1;
2097
- } else {
2098
- canvas.width = width;
2099
- canvas.height = height;
2100
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
2385
+ if (!ctx || width <= 0 || height <= 0) {
2386
+ return new Uint8ClampedArray();
2101
2387
  }
2388
+ canvas.width = width;
2389
+ canvas.height = height;
2390
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
2102
2391
  return ctx.getImageData(0, 0, canvas.width, canvas.height).data;
2103
2392
  } finally {
2104
- canvas.parentNode.removeChild(canvas);
2393
+ var _canvas$parentNode;
2394
+ canvas === null || canvas === void 0 || (_canvas$parentNode = canvas.parentNode) === null || _canvas$parentNode === void 0 || _canvas$parentNode.removeChild(canvas);
2105
2395
  }
2106
2396
  },
2107
2397
  /**
@@ -2121,20 +2411,19 @@ var LeUtils = {
2121
2411
  var ctx = canvas.getContext('2d');
2122
2412
  var width = Math.floor(image.width);
2123
2413
  var height = Math.floor(image.height);
2124
- if (width <= 0 || height <= 0) {
2125
- canvas.width = 1;
2126
- canvas.height = 1;
2127
- } else {
2128
- canvas.width = width;
2129
- canvas.height = height;
2130
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
2414
+ if (!ctx || width <= 0 || height <= 0) {
2415
+ return LeUtils.getEmptyImageSrc();
2131
2416
  }
2417
+ canvas.width = width;
2418
+ canvas.height = height;
2419
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
2132
2420
  ctx.globalCompositeOperation = 'source-in';
2133
2421
  ctx.fillStyle = color;
2134
2422
  ctx.fillRect(0, 0, canvas.width, canvas.height);
2135
2423
  return canvas.toDataURL('image/png');
2136
2424
  } finally {
2137
- canvas.parentNode.removeChild(canvas);
2425
+ var _canvas$parentNode2;
2426
+ canvas === null || canvas === void 0 || (_canvas$parentNode2 = canvas.parentNode) === null || _canvas$parentNode2 === void 0 || _canvas$parentNode2.removeChild(canvas);
2138
2427
  }
2139
2428
  },
2140
2429
  /**
@@ -2156,14 +2445,19 @@ var LeUtils = {
2156
2445
  * @returns {number[]}
2157
2446
  */
2158
2447
  hexToRgb: function hexToRgb(hexstring) {
2448
+ var _hexstring$match;
2449
+ var initialHexstring = hexstring;
2159
2450
  hexstring = hexstring.replace(/[^0-9A-F]/gi, '');
2160
2451
  var hasAlpha = hexstring.length === 4 || hexstring.length === 8;
2161
2452
  while (hexstring.length < 6) {
2162
2453
  hexstring = hexstring.replace(/(.)/g, '$1$1');
2163
2454
  }
2164
- var result = hexstring.match(/\w{2}/g).map(function (a) {
2455
+ var result = (_hexstring$match = hexstring.match(/\w{2}/g)) === null || _hexstring$match === void 0 ? void 0 : _hexstring$match.map(function (a) {
2165
2456
  return parseInt(a, 16);
2166
2457
  });
2458
+ if (!result || result.length < 3) {
2459
+ throw new Error('Invalid hex color: "' + hexstring + '" (was given "' + initialHexstring + '")');
2460
+ }
2167
2461
  return [result[0], result[1], result[2]].concat(_toConsumableArray(hasAlpha ? [result[3]] : []));
2168
2462
  },
2169
2463
  /**
@@ -2178,12 +2472,10 @@ var LeUtils = {
2178
2472
  var b = rgb[2] / 255;
2179
2473
  var max = Math.max(r, g, b);
2180
2474
  var min = Math.min(r, g, b);
2181
- var h,
2182
- s,
2183
- l = (max + min) / 2;
2184
- if (max === min) {
2185
- h = s = 0;
2186
- } else {
2475
+ var h = 0;
2476
+ var s = 0;
2477
+ var l = (max + min) / 2;
2478
+ if (max !== min) {
2187
2479
  var d = max - min;
2188
2480
  s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
2189
2481
  switch (max) {
@@ -2230,10 +2522,10 @@ var LeUtils = {
2230
2522
  var h = hsl[0];
2231
2523
  var s = hsl[1];
2232
2524
  var l = hsl[2];
2233
- var r, g, b;
2234
- if (s === 0) {
2235
- r = g = b = l;
2236
- } else {
2525
+ var r = 1;
2526
+ var g = 1;
2527
+ var b = 1;
2528
+ if (s !== 0) {
2237
2529
  var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
2238
2530
  var p = 2 * l - q;
2239
2531
  r = hue2rgb(p, q, h + 1 / 3);
@@ -2271,13 +2563,13 @@ var LeUtils = {
2271
2563
  *
2272
2564
  * Returns a number:
2273
2565
  *
2274
- * <pre>
2275
- * < 1.0 is not perceptible by human eyes
2566
+ * ```js
2567
+ * < 1 is not perceptible by human eyes
2276
2568
  * 1-2 is perceptible through close observation
2277
2569
  * 2-10 is perceptible at a glance
2278
2570
  * 11-49 is more similar than opposite
2279
2571
  * 100 is exactly the opposite color
2280
- * </pre>
2572
+ * ```
2281
2573
  *
2282
2574
  * @param {number[]} rgbA
2283
2575
  * @param {number[]} rgbB
@@ -2293,13 +2585,13 @@ var LeUtils = {
2293
2585
  *
2294
2586
  * Returns a number:
2295
2587
  *
2296
- * <pre>
2297
- * < 1.0 is not perceptible by human eyes
2588
+ * ```js
2589
+ * < 1 is not perceptible by human eyes
2298
2590
  * 1-2 is perceptible through close observation
2299
2591
  * 2-10 is perceptible at a glance
2300
2592
  * 11-49 is more similar than opposite
2301
2593
  * 100 is exactly the opposite color
2302
- * </pre>
2594
+ * ```
2303
2595
  *
2304
2596
  * @param {number[]} labA
2305
2597
  * @param {number[]} labB
@@ -2328,16 +2620,16 @@ var LeUtils = {
2328
2620
  *
2329
2621
  * Usage:
2330
2622
  *
2331
- * <pre>
2623
+ * ```js
2332
2624
  * LeUtils.getRgbOfGradient({
2333
2625
  * 0: [255, 0, 0],
2334
2626
  * 33: [255, 255, 0],
2335
2627
  * 66: [0, 255, 0],
2336
2628
  * 100:[0, 255, 255],
2337
2629
  * }, 45.1234);
2338
- * </pre>
2630
+ * ```
2339
2631
  *
2340
- * @param {{[percentage]: number[]}} gradient
2632
+ * @param {{percentage?:number[]}} gradient
2341
2633
  * @param {number} percentage
2342
2634
  * @returns {number[]}
2343
2635
  */
@@ -2356,11 +2648,13 @@ var LeUtils = {
2356
2648
  }
2357
2649
  });
2358
2650
  if (closest === null) {
2359
- return null;
2651
+ return [0, 0, 0];
2360
2652
  }
2361
2653
  closest = closest[0];
2362
- var higher = 99999;
2363
- var lower = -99999;
2654
+ var HIGHER = 99999;
2655
+ var LOWER = -99999;
2656
+ var higher = HIGHER;
2657
+ var lower = LOWER;
2364
2658
  LeUtils.each(gradient, function (color, percent) {
2365
2659
  percent = INT_LAX(percent);
2366
2660
  if (percent < closest) {
@@ -2374,15 +2668,9 @@ var LeUtils = {
2374
2668
  }
2375
2669
  }
2376
2670
  });
2377
- if (higher === 99999) {
2378
- higher = null;
2379
- }
2380
- if (lower === -99999) {
2381
- lower = null;
2382
- }
2383
- if (higher === null && lower === null || higher === lower) {
2671
+ if (higher === HIGHER && lower === LOWER || higher === lower) {
2384
2672
  return gradient[closest];
2385
- } else if (higher !== null && lower !== null) {
2673
+ } else if (higher !== HIGHER && lower !== LOWER) {
2386
2674
  var higherDifference = Math.abs(higher - percentage);
2387
2675
  var lowerDifference = Math.abs(percentage - lower);
2388
2676
  if (higherDifference > lowerDifference) {
@@ -2390,7 +2678,7 @@ var LeUtils = {
2390
2678
  } else {
2391
2679
  lower = closest;
2392
2680
  }
2393
- } else if (lower === null) {
2681
+ } else if (lower === LOWER) {
2394
2682
  lower = closest;
2395
2683
  } else {
2396
2684
  higher = closest;
@@ -2430,7 +2718,7 @@ var LeUtils = {
2430
2718
  * @returns {string}
2431
2719
  */
2432
2720
  btoa: function (_btoa) {
2433
- function btoa(_x15) {
2721
+ function btoa(_x13) {
2434
2722
  return _btoa.apply(this, arguments);
2435
2723
  }
2436
2724
  btoa.toString = function () {
@@ -2450,7 +2738,7 @@ var LeUtils = {
2450
2738
  * @returns {string}
2451
2739
  */
2452
2740
  atob: function (_atob) {
2453
- function atob(_x16) {
2741
+ function atob(_x14) {
2454
2742
  return _atob.apply(this, arguments);
2455
2743
  }
2456
2744
  atob.toString = function () {
@@ -2503,9 +2791,14 @@ var LeUtils = {
2503
2791
  * @returns {string}
2504
2792
  */
2505
2793
  hexToBase64: function hexToBase64(hexstring) {
2506
- return LeUtils.btoa(hexstring.replace(/[^0-9A-F]/gi, '').match(/\w{2}/g).map(function (a) {
2794
+ var _hexstring$replace$ma;
2795
+ var hexResult = (_hexstring$replace$ma = hexstring.replace(/[^0-9A-F]/gi, '').match(/\w{2}/g)) === null || _hexstring$replace$ma === void 0 || (_hexstring$replace$ma = _hexstring$replace$ma.map(function (a) {
2507
2796
  return String.fromCharCode(parseInt(a, 16));
2508
- }).join(''));
2797
+ })) === null || _hexstring$replace$ma === void 0 ? void 0 : _hexstring$replace$ma.join('');
2798
+ if (!hexResult) {
2799
+ throw new Error('Invalid hex string: "' + hexstring + '"');
2800
+ }
2801
+ return LeUtils.btoa(hexResult);
2509
2802
  },
2510
2803
  /**
2511
2804
  * Converts a base64 string into bytes (Uint8Array).
@@ -2525,7 +2818,7 @@ var LeUtils = {
2525
2818
  /**
2526
2819
  * Converts bytes into a base64 string.
2527
2820
  *
2528
- * @param {ArrayLike<number>|ArrayBufferLike} arraybuffer
2821
+ * @param {ArrayLike<number>|ArrayBuffer} arraybuffer
2529
2822
  * @returns {string}
2530
2823
  */
2531
2824
  bytesToBase64: function bytesToBase64(arraybuffer) {
@@ -2569,10 +2862,8 @@ var LeUtils = {
2569
2862
  return;
2570
2863
  }
2571
2864
  try {
2572
- result = JSON.parse(result);
2573
- if (typeof result['-'] !== 'undefined') {
2574
- return result['-'];
2575
- }
2865
+ var _JSON$parse;
2866
+ return (_JSON$parse = JSON.parse(result)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse['-'];
2576
2867
  } catch (e) {}
2577
2868
  },
2578
2869
  /**
@@ -2660,8 +2951,8 @@ var LeUtils = {
2660
2951
  * This way, you can have values that aren't the same be treated as if they are. This can be used to deal with issues such as floating point errors for example.
2661
2952
  *
2662
2953
  * @param {*[]} elements
2663
- * @param {Function} comparator
2664
- * @returns {{getElements: (function(): *[]), getComparator: (function(): Function), size: (function(): number), isEmpty: (function(): boolean), contains: (function(*): boolean), first: (function(): *|undefined), last: (function(): *|undefined), pollFirst: (function(): *|undefined), pollLast: (function(): *|undefined), add: function(*), addAll: function(*[]|object), getEqualValue: (function(*): (*)), getEqualValueOrAdd: (function(*): (*))}}
2954
+ * @param {(valueA:*, valueB:*) => number} comparator
2955
+ * @returns {{getElements:(()=>*[]), getComparator:(()=>((valueA:*,valueB:*)=>number)), size:(()=>number), isEmpty:(()=>boolean), contains:((value:*)=>boolean), first:(()=>*|undefined), last:(()=>*|undefined), pollFirst:(()=>*|undefined), pollLast:(()=>*|undefined), add:((value:*)=>void), addAll:((values:*)=>void), getEqualValue:((value:*)=>*), getEqualValueOrAdd:((value:*)=>*)}}
2665
2956
  */
2666
2957
  createTreeSet: function createTreeSet(elements, comparator) {
2667
2958
  comparator = comparator || LeUtils.compare;
@@ -2711,7 +3002,7 @@ var LeUtils = {
2711
3002
  /**
2712
3003
  * Returns the comparator of the set.
2713
3004
  *
2714
- * @returns {Function}
3005
+ * @returns {(valueA:*, valueB:*) => number}
2715
3006
  */
2716
3007
  getComparator: function getComparator() {
2717
3008
  return comparator;
@@ -2788,7 +3079,7 @@ var LeUtils = {
2788
3079
  /**
2789
3080
  * Adds all the given values to the set. Will only do so if no equal value already exists.
2790
3081
  *
2791
- * @param {*[]|object} values
3082
+ * @param {*} values
2792
3083
  */
2793
3084
  addAll: function addAll(values) {
2794
3085
  LeUtils.each(values, treeSet.add);
@@ -2824,7 +3115,7 @@ var LeUtils = {
2824
3115
  return treeSet;
2825
3116
  },
2826
3117
  /**
2827
- * @typedef {Object} LeUtils~TransactionalValue
3118
+ * @typedef {Object} LeUtils_TransactionalValue
2828
3119
  * @property {*} value
2829
3120
  * @property {{id:string, value:*}[]} changes
2830
3121
  */
@@ -2837,7 +3128,7 @@ var LeUtils = {
2837
3128
  * This allows you to make multiple unconfirmed changes, and confirm or cancel each of them individually at any time.
2838
3129
  *
2839
3130
  * @param {*} [value]
2840
- * @returns {LeUtils~TransactionalValue}
3131
+ * @returns {LeUtils_TransactionalValue}
2841
3132
  */
2842
3133
  createTransactionalValue: function createTransactionalValue(value) {
2843
3134
  if (typeof value === 'undefined') {
@@ -2851,7 +3142,7 @@ var LeUtils = {
2851
3142
  /**
2852
3143
  * Returns true if the given value is a valid TransactionalValue, returns false if it isn't.
2853
3144
  *
2854
- * @param {LeUtils~TransactionalValue} transactionalValue
3145
+ * @param {LeUtils_TransactionalValue} transactionalValue
2855
3146
  * @returns {boolean}
2856
3147
  */
2857
3148
  isTransactionalValueValid: function isTransactionalValueValid(transactionalValue) {
@@ -2860,7 +3151,7 @@ var LeUtils = {
2860
3151
  /**
2861
3152
  * Returns true if the given value is a TransactionalValue, false otherwise.
2862
3153
  *
2863
- * @param {LeUtils~TransactionalValue} transactionalValue
3154
+ * @param {LeUtils_TransactionalValue} transactionalValue
2864
3155
  * @returns {string}
2865
3156
  */
2866
3157
  transactionalValueToString: function transactionalValueToString(transactionalValue) {
@@ -2879,7 +3170,7 @@ var LeUtils = {
2879
3170
  /**
2880
3171
  * Sets the committed value of the given TransactionalValue to the given value. Clears out the previously uncommitted changes.
2881
3172
  *
2882
- * @param {LeUtils~TransactionalValue} transactionalValue
3173
+ * @param {LeUtils_TransactionalValue} transactionalValue
2883
3174
  * @param {*} value
2884
3175
  */
2885
3176
  transactionSetAndCommit: function transactionSetAndCommit(transactionalValue, value) {
@@ -2894,7 +3185,7 @@ var LeUtils = {
2894
3185
  * Sets the value of the given TransactionalValue to the given value, without yet committing it, meaning it can be committed or cancelled later.
2895
3186
  * It returns the ID of the change, which can be used to commit or cancel the change later.
2896
3187
  *
2897
- * @param {LeUtils~TransactionalValue} transactionalValue
3188
+ * @param {LeUtils_TransactionalValue} transactionalValue
2898
3189
  * @param {*} value
2899
3190
  * @returns {string}
2900
3191
  */
@@ -2914,7 +3205,7 @@ var LeUtils = {
2914
3205
  * Commits the change with the given ID, making it the new committed value.
2915
3206
  * Returns true if the change was found and committed, returns false if it was already overwritten by a newer committed change.
2916
3207
  *
2917
- * @param {LeUtils~TransactionalValue} transactionalValue
3208
+ * @param {LeUtils_TransactionalValue} transactionalValue
2918
3209
  * @param {string} changeId
2919
3210
  * @returns {boolean}
2920
3211
  */
@@ -2932,7 +3223,7 @@ var LeUtils = {
2932
3223
  * Cancels the change with the given ID, removing it from the uncommitted changes.
2933
3224
  * Returns true if the change was found and removed, returns false if it was already overwritten by a newer committed change.
2934
3225
  *
2935
- * @param {LeUtils~TransactionalValue} transactionalValue
3226
+ * @param {LeUtils_TransactionalValue} transactionalValue
2936
3227
  * @param {string} changeId
2937
3228
  * @returns {boolean}
2938
3229
  */
@@ -2949,7 +3240,7 @@ var LeUtils = {
2949
3240
  * Returns true if the change was found, meaning it can still make a difference to the final committed value of this TransactionalValue.
2950
3241
  * Returns false if it was already overwritten by a newer committed change, meaning that this change can no longer make a difference to the final committed value of this TransactionalValue.
2951
3242
  *
2952
- * @param {LeUtils~TransactionalValue} transactionalValue
3243
+ * @param {LeUtils_TransactionalValue} transactionalValue
2953
3244
  * @param {string} changeId
2954
3245
  * @returns {boolean}
2955
3246
  */
@@ -2960,7 +3251,7 @@ var LeUtils = {
2960
3251
  /**
2961
3252
  * Returns the committed value of the given TransactionalValue.
2962
3253
  *
2963
- * @param {LeUtils~TransactionalValue} transactionalValue
3254
+ * @param {LeUtils_TransactionalValue} transactionalValue
2964
3255
  * @returns {*}
2965
3256
  */
2966
3257
  transactionGetCommittedValue: function transactionGetCommittedValue(transactionalValue) {
@@ -2970,7 +3261,7 @@ var LeUtils = {
2970
3261
  /**
2971
3262
  * Returns the value (including any uncommitted changes made to it) of the given TransactionalValue.
2972
3263
  *
2973
- * @param {LeUtils~TransactionalValue} transactionalValue
3264
+ * @param {LeUtils_TransactionalValue} transactionalValue
2974
3265
  * @returns {*}
2975
3266
  */
2976
3267
  transactionGetValue: function transactionGetValue(transactionalValue) {
@@ -3032,15 +3323,17 @@ var LeUtils = {
3032
3323
  * ```
3033
3324
  *
3034
3325
  * @param {string} name
3035
- * @returns {{worker: Worker, sendMessage: function(Object, {timeout: number|undefined}|undefined): Promise<Object>}}
3326
+ * @returns {{worker:Worker|null, sendMessage:(data:Object,options:{timeout:number|undefined}|undefined)=>Promise<Object>}}
3036
3327
  */
3037
3328
  createWorkerThread: function createWorkerThread(name) {
3038
3329
  if (typeof window === 'undefined' || typeof Worker === 'undefined') {
3039
3330
  return {
3040
3331
  worker: null,
3041
- sendMessage: new Promise(function (resolve, reject) {
3042
- reject('Workers are not supported in this environment');
3043
- })
3332
+ sendMessage: function sendMessage(data, options) {
3333
+ return new Promise(function (resolve, reject) {
3334
+ reject('Workers are not supported in this environment');
3335
+ });
3336
+ }
3044
3337
  };
3045
3338
  }
3046
3339
  var worker = new Worker('/workers/' + name + '.worker.js');
@@ -3090,7 +3383,7 @@ var LeUtils = {
3090
3383
  *
3091
3384
  * @param {string} workerName
3092
3385
  * @param {Object} data
3093
- * @param {{timeout: number|undefined}} [options]
3386
+ * @param {{timeout:number|undefined}} [options]
3094
3387
  * @returns {Promise<Object>}
3095
3388
  */
3096
3389
  sendWorkerMessage: function () {
@@ -3128,8 +3421,8 @@ var LeUtils = {
3128
3421
  }
3129
3422
  var inputTypes = ['text', 'search', 'email', 'number', 'password', 'tel', 'time', 'url', 'week', 'month', 'date', 'datetime-local'];
3130
3423
  return function () {
3131
- var _document, _document2;
3132
- return !(((_document = document) === null || _document === void 0 || (_document = _document.activeElement) === null || _document === void 0 || (_document = _document.tagName) === null || _document === void 0 ? void 0 : _document.toLowerCase()) === 'input' && inputTypes.includes((_document2 = document) === null || _document2 === void 0 || (_document2 = _document2.activeElement) === null || _document2 === void 0 || (_document2 = _document2.type) === null || _document2 === void 0 ? void 0 : _document2.toLowerCase()));
3424
+ var _document, _document$activeEleme, _document2;
3425
+ return !(((_document = document) === null || _document === void 0 || (_document = _document.activeElement) === null || _document === void 0 || (_document = _document.tagName) === null || _document === void 0 ? void 0 : _document.toLowerCase()) === 'input' && inputTypes.includes((_document$activeEleme = (_document2 = document) === null || _document2 === void 0 || (_document2 = _document2.activeElement) === null || _document2 === void 0 || (_document2 = _document2.getAttribute('type')) === null || _document2 === void 0 ? void 0 : _document2.toLowerCase()) !== null && _document$activeEleme !== void 0 ? _document$activeEleme : ''));
3133
3426
  };
3134
3427
  }(),
3135
3428
  /**