@creejs/commons-lang 2.1.33 → 2.1.35

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.
@@ -2838,6 +2838,26 @@ function chunk (array, size) {
2838
2838
  return chunked
2839
2839
  }
2840
2840
 
2841
+ // owned
2842
+ /**
2843
+ * @template T
2844
+ * @param {Iterator<T>} iterator
2845
+ * @param {number} howMany
2846
+ * @returns {Array<T>}
2847
+ */
2848
+ function take$1 (iterator, howMany) {
2849
+ const rtnVal = [];
2850
+ let next;
2851
+ for (let i = 0; i < howMany && !(next = iterator.next()).done; i++) {
2852
+ rtnVal.push(next.value);
2853
+ }
2854
+ return rtnVal
2855
+ }
2856
+
2857
+ var IteratorUtils = {
2858
+ take: take$1
2859
+ };
2860
+
2841
2861
  // owned
2842
2862
 
2843
2863
  /**
@@ -2849,13 +2869,10 @@ function chunk (array, size) {
2849
2869
  function length (iterable) {
2850
2870
  TypeAssert.assertIterable(iterable);
2851
2871
  // @ts-ignore
2852
- if (typeof iterable.length !== 'undefined') {
2853
- // @ts-ignore
2854
- return iterable.length
2855
- // @ts-ignore
2856
- } else if (typeof iterable.size !== 'undefined') {
2857
- // @ts-ignore
2858
- return iterable.size
2872
+ const length = iterable.length ?? iterable.size;
2873
+ // @ts-ignore
2874
+ if (typeof length === 'number') {
2875
+ return length
2859
2876
  }
2860
2877
  let counter = 0;
2861
2878
  // eslint-disable-next-line no-unused-vars
@@ -2865,8 +2882,28 @@ function length (iterable) {
2865
2882
  return counter
2866
2883
  }
2867
2884
 
2868
- var IteratorUtils = {
2869
- length
2885
+ /**
2886
+ * @template T
2887
+ * @param {Iterable<T>} iterable
2888
+ * @param {number} howMany
2889
+ * @returns {Array<T>}
2890
+ */
2891
+ function take (iterable, howMany) {
2892
+ // if (length(iterable) <= howMany) {
2893
+ // return [...iterable]
2894
+ // }
2895
+ const iterator = iterable[Symbol.iterator]();
2896
+ const rtnVal = [];
2897
+ let next;
2898
+ for (let i = 0; i < howMany && !(next = iterator.next()).done; i++) {
2899
+ rtnVal.push(next.value);
2900
+ }
2901
+ return rtnVal
2902
+ }
2903
+
2904
+ var IterableUtils = {
2905
+ length,
2906
+ take
2870
2907
  };
2871
2908
 
2872
2909
  /**
@@ -2893,7 +2930,8 @@ var index = {
2893
2930
  ArrayBufferUtils,
2894
2931
  TimeUtils,
2895
2932
  ArrayUtils,
2896
- IteratorUtils
2933
+ IteratorUtils,
2934
+ IterableUtils
2897
2935
  };
2898
2936
 
2899
2937
  exports.AggregatedError = AggregatedError;
@@ -2903,6 +2941,7 @@ exports.ClassProxyUtils = ClassProxyUtils;
2903
2941
  exports.Exec = ExecUtils;
2904
2942
  exports.ExecUtils = ExecUtils;
2905
2943
  exports.InstanceProxyUtils = InstanceProxyUtils;
2944
+ exports.IterableUtils = IterableUtils;
2906
2945
  exports.IteratorUtils = IteratorUtils;
2907
2946
  exports.Lang = LangUtils;
2908
2947
  exports.LangUtils = LangUtils;