@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.
@@ -168,6 +168,7 @@
168
168
  */
169
169
 
170
170
  var LangUtils = {
171
+ get,
171
172
  constructorName,
172
173
  defaults,
173
174
  extend,
@@ -179,6 +180,31 @@
179
180
  deepCloneToPlainObject
180
181
  };
181
182
 
183
+ /**
184
+ *
185
+ * @param {{[key:string]:any}} obj
186
+ * @param {string} path
187
+ * @param {any} [defaultValue]
188
+ * @returns
189
+ */
190
+ function get (obj, path, defaultValue) {
191
+ if (obj == null) {
192
+ return defaultValue
193
+ }
194
+ if (typeof path !== 'string') {
195
+ throw new Error('"path" must be a string')
196
+ }
197
+ const pathArray = path.split('.');
198
+ let current = obj;
199
+ for (const key of pathArray) {
200
+ if (current[key] === undefined) {
201
+ return defaultValue
202
+ }
203
+ current = current[key];
204
+ }
205
+ return current
206
+ }
207
+
182
208
  /**
183
209
  * Gets the constructor name of a value.
184
210
  * @param {*} value - The value to check.
@@ -765,7 +791,8 @@
765
791
  assertBigInt64Array,
766
792
  assertBigUint64Array,
767
793
  assertTypedArray,
768
- assertArrayBuffer
794
+ assertArrayBuffer,
795
+ assertIterable
769
796
  };
770
797
  /**
771
798
  * if value is not Array, throw error
@@ -1131,6 +1158,18 @@
1131
1158
  }
1132
1159
  }
1133
1160
 
1161
+ /**
1162
+ * Asserts that the given value is Iterable
1163
+ * @param {*} value - The value to check.
1164
+ * @param {string} [paramName] - Optional parameter name for error message.
1165
+ * @throws {Error} Throws an error if the value is not Iterable
1166
+ */
1167
+ function assertIterable (value, paramName) {
1168
+ if (!isIterable(value)) {
1169
+ throw new Error(`${paramName ? '"' + paramName + '" ' : ''}Not Iterable`)
1170
+ }
1171
+ }
1172
+
1134
1173
  // 3rd
1135
1174
  // internal
1136
1175
  // owned
@@ -2801,6 +2840,35 @@
2801
2840
  return chunked
2802
2841
  }
2803
2842
 
2843
+ // owned
2844
+
2845
+ /**
2846
+ * @template T
2847
+ * @param {Iterable<T>} 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
+
2804
2872
  /**
2805
2873
  * @module Lang
2806
2874
  * @description Core language utilities for type checking, string manipulation, and common operations.
@@ -2824,7 +2892,8 @@
2824
2892
  TypedArrayUtils,
2825
2893
  ArrayBufferUtils,
2826
2894
  TimeUtils,
2827
- ArrayUtils
2895
+ ArrayUtils,
2896
+ IteratorUtils
2828
2897
  };
2829
2898
 
2830
2899
  exports.AggregatedError = AggregatedError;
@@ -2834,6 +2903,7 @@
2834
2903
  exports.Exec = ExecUtils;
2835
2904
  exports.ExecUtils = ExecUtils;
2836
2905
  exports.InstanceProxyUtils = InstanceProxyUtils;
2906
+ exports.IteratorUtils = IteratorUtils;
2837
2907
  exports.Lang = LangUtils;
2838
2908
  exports.LangUtils = LangUtils;
2839
2909
  exports.PromiseUtils = PromiseUtils;