@creejs/commons-lang 2.1.31 → 2.1.33

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.
@@ -789,7 +789,8 @@ var TypeAssert = {
789
789
  assertBigInt64Array,
790
790
  assertBigUint64Array,
791
791
  assertTypedArray,
792
- assertArrayBuffer
792
+ assertArrayBuffer,
793
+ assertIterable
793
794
  };
794
795
  /**
795
796
  * if value is not Array, throw error
@@ -1155,6 +1156,18 @@ function assertArrayBuffer (value, paramName) {
1155
1156
  }
1156
1157
  }
1157
1158
 
1159
+ /**
1160
+ * Asserts that the given value is Iterable
1161
+ * @param {*} value - The value to check.
1162
+ * @param {string} [paramName] - Optional parameter name for error message.
1163
+ * @throws {Error} Throws an error if the value is not Iterable
1164
+ */
1165
+ function assertIterable (value, paramName) {
1166
+ if (!isIterable(value)) {
1167
+ throw new Error(`${paramName ? '"' + paramName + '" ' : ''}Not Iterable`)
1168
+ }
1169
+ }
1170
+
1158
1171
  // 3rd
1159
1172
  // internal
1160
1173
  // owned
@@ -2825,6 +2838,37 @@ function chunk (array, size) {
2825
2838
  return chunked
2826
2839
  }
2827
2840
 
2841
+ // owned
2842
+
2843
+ /**
2844
+ * @template T
2845
+ * @param {Iterable<T>} iterable
2846
+ * @returns {number}
2847
+ * @throws {Error} Not Iterable
2848
+ */
2849
+ function length (iterable) {
2850
+ TypeAssert.assertIterable(iterable);
2851
+ // @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
2859
+ }
2860
+ let counter = 0;
2861
+ // eslint-disable-next-line no-unused-vars
2862
+ for (const _item of iterable) {
2863
+ counter++;
2864
+ }
2865
+ return counter
2866
+ }
2867
+
2868
+ var IteratorUtils = {
2869
+ length
2870
+ };
2871
+
2828
2872
  /**
2829
2873
  * @module Lang
2830
2874
  * @description Core language utilities for type checking, string manipulation, and common operations.
@@ -2848,7 +2892,8 @@ var index = {
2848
2892
  TypedArrayUtils,
2849
2893
  ArrayBufferUtils,
2850
2894
  TimeUtils,
2851
- ArrayUtils
2895
+ ArrayUtils,
2896
+ IteratorUtils
2852
2897
  };
2853
2898
 
2854
2899
  exports.AggregatedError = AggregatedError;
@@ -2858,6 +2903,7 @@ exports.ClassProxyUtils = ClassProxyUtils;
2858
2903
  exports.Exec = ExecUtils;
2859
2904
  exports.ExecUtils = ExecUtils;
2860
2905
  exports.InstanceProxyUtils = InstanceProxyUtils;
2906
+ exports.IteratorUtils = IteratorUtils;
2861
2907
  exports.Lang = LangUtils;
2862
2908
  exports.LangUtils = LangUtils;
2863
2909
  exports.PromiseUtils = PromiseUtils;