@creejs/commons-lang 2.1.30 → 2.1.32

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.
@@ -166,6 +166,7 @@ class AggregatedError extends Error {
166
166
  */
167
167
 
168
168
  var LangUtils = {
169
+ get,
169
170
  constructorName,
170
171
  defaults,
171
172
  extend,
@@ -177,6 +178,31 @@ var LangUtils = {
177
178
  deepCloneToPlainObject
178
179
  };
179
180
 
181
+ /**
182
+ *
183
+ * @param {{[key:string]:any}} obj
184
+ * @param {string} path
185
+ * @param {any} [defaultValue]
186
+ * @returns
187
+ */
188
+ function get (obj, path, defaultValue) {
189
+ if (obj == null) {
190
+ return defaultValue
191
+ }
192
+ if (typeof path !== 'string') {
193
+ throw new Error('"path" must be a string')
194
+ }
195
+ const pathArray = path.split('.');
196
+ let current = obj;
197
+ for (const key of pathArray) {
198
+ if (current[key] === undefined) {
199
+ return defaultValue
200
+ }
201
+ current = current[key];
202
+ }
203
+ return current
204
+ }
205
+
180
206
  /**
181
207
  * Gets the constructor name of a value.
182
208
  * @param {*} value - The value to check.
@@ -763,7 +789,8 @@ var TypeAssert = {
763
789
  assertBigInt64Array,
764
790
  assertBigUint64Array,
765
791
  assertTypedArray,
766
- assertArrayBuffer
792
+ assertArrayBuffer,
793
+ assertIterable
767
794
  };
768
795
  /**
769
796
  * if value is not Array, throw error
@@ -1129,6 +1156,18 @@ function assertArrayBuffer (value, paramName) {
1129
1156
  }
1130
1157
  }
1131
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
+
1132
1171
  // 3rd
1133
1172
  // internal
1134
1173
  // owned
@@ -2799,6 +2838,35 @@ function chunk (array, size) {
2799
2838
  return chunked
2800
2839
  }
2801
2840
 
2841
+ // owned
2842
+
2843
+ /**
2844
+ * @template T
2845
+ * @param {Iterable<T>} iterable
2846
+ */
2847
+ function length (iterable) {
2848
+ TypeAssert.assertIterable(iterable);
2849
+ // @ts-ignore
2850
+ if (typeof iterable.length !== 'undefined') {
2851
+ // @ts-ignore
2852
+ return iterable.length
2853
+ // @ts-ignore
2854
+ } else if (typeof iterable.size !== 'undefined') {
2855
+ // @ts-ignore
2856
+ return iterable.size
2857
+ }
2858
+ let counter = 0;
2859
+ // eslint-disable-next-line no-unused-vars
2860
+ for (const _item of iterable) {
2861
+ counter++;
2862
+ }
2863
+ return counter
2864
+ }
2865
+
2866
+ var IteratorUtils = {
2867
+ length
2868
+ };
2869
+
2802
2870
  /**
2803
2871
  * @module Lang
2804
2872
  * @description Core language utilities for type checking, string manipulation, and common operations.
@@ -2822,7 +2890,8 @@ var index = {
2822
2890
  TypedArrayUtils,
2823
2891
  ArrayBufferUtils,
2824
2892
  TimeUtils,
2825
- ArrayUtils
2893
+ ArrayUtils,
2894
+ IteratorUtils
2826
2895
  };
2827
2896
 
2828
2897
  exports.AggregatedError = AggregatedError;
@@ -2832,6 +2901,7 @@ exports.ClassProxyUtils = ClassProxyUtils;
2832
2901
  exports.Exec = ExecUtils;
2833
2902
  exports.ExecUtils = ExecUtils;
2834
2903
  exports.InstanceProxyUtils = InstanceProxyUtils;
2904
+ exports.IteratorUtils = IteratorUtils;
2835
2905
  exports.Lang = LangUtils;
2836
2906
  exports.LangUtils = LangUtils;
2837
2907
  exports.PromiseUtils = PromiseUtils;