@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.
- package/dist/cjs/index-dev.cjs +48 -2
- package/dist/cjs/index-dev.cjs.map +1 -1
- package/dist/cjs/index-min.cjs +1 -1
- package/dist/cjs/index-min.cjs.map +1 -1
- package/dist/esm/index-dev.js +48 -3
- package/dist/esm/index-dev.js.map +1 -1
- package/dist/esm/index-min.js +1 -1
- package/dist/esm/index-min.js.map +1 -1
- package/dist/umd/index.dev.js +48 -2
- package/dist/umd/index.dev.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +3 -1
- package/types/iterator-utils.d.ts +11 -0
- package/types/type-assert.d.ts +8 -0
package/dist/umd/index.dev.js
CHANGED
|
@@ -791,7 +791,8 @@
|
|
|
791
791
|
assertBigInt64Array,
|
|
792
792
|
assertBigUint64Array,
|
|
793
793
|
assertTypedArray,
|
|
794
|
-
assertArrayBuffer
|
|
794
|
+
assertArrayBuffer,
|
|
795
|
+
assertIterable
|
|
795
796
|
};
|
|
796
797
|
/**
|
|
797
798
|
* if value is not Array, throw error
|
|
@@ -1157,6 +1158,18 @@
|
|
|
1157
1158
|
}
|
|
1158
1159
|
}
|
|
1159
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
|
+
|
|
1160
1173
|
// 3rd
|
|
1161
1174
|
// internal
|
|
1162
1175
|
// owned
|
|
@@ -2827,6 +2840,37 @@
|
|
|
2827
2840
|
return chunked
|
|
2828
2841
|
}
|
|
2829
2842
|
|
|
2843
|
+
// owned
|
|
2844
|
+
|
|
2845
|
+
/**
|
|
2846
|
+
* @template T
|
|
2847
|
+
* @param {Iterable<T>} iterable
|
|
2848
|
+
* @returns {number}
|
|
2849
|
+
* @throws {Error} Not Iterable
|
|
2850
|
+
*/
|
|
2851
|
+
function length (iterable) {
|
|
2852
|
+
TypeAssert.assertIterable(iterable);
|
|
2853
|
+
// @ts-ignore
|
|
2854
|
+
if (typeof iterable.length !== 'undefined') {
|
|
2855
|
+
// @ts-ignore
|
|
2856
|
+
return iterable.length
|
|
2857
|
+
// @ts-ignore
|
|
2858
|
+
} else if (typeof iterable.size !== 'undefined') {
|
|
2859
|
+
// @ts-ignore
|
|
2860
|
+
return iterable.size
|
|
2861
|
+
}
|
|
2862
|
+
let counter = 0;
|
|
2863
|
+
// eslint-disable-next-line no-unused-vars
|
|
2864
|
+
for (const _item of iterable) {
|
|
2865
|
+
counter++;
|
|
2866
|
+
}
|
|
2867
|
+
return counter
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
var IteratorUtils = {
|
|
2871
|
+
length
|
|
2872
|
+
};
|
|
2873
|
+
|
|
2830
2874
|
/**
|
|
2831
2875
|
* @module Lang
|
|
2832
2876
|
* @description Core language utilities for type checking, string manipulation, and common operations.
|
|
@@ -2850,7 +2894,8 @@
|
|
|
2850
2894
|
TypedArrayUtils,
|
|
2851
2895
|
ArrayBufferUtils,
|
|
2852
2896
|
TimeUtils,
|
|
2853
|
-
ArrayUtils
|
|
2897
|
+
ArrayUtils,
|
|
2898
|
+
IteratorUtils
|
|
2854
2899
|
};
|
|
2855
2900
|
|
|
2856
2901
|
exports.AggregatedError = AggregatedError;
|
|
@@ -2860,6 +2905,7 @@
|
|
|
2860
2905
|
exports.Exec = ExecUtils;
|
|
2861
2906
|
exports.ExecUtils = ExecUtils;
|
|
2862
2907
|
exports.InstanceProxyUtils = InstanceProxyUtils;
|
|
2908
|
+
exports.IteratorUtils = IteratorUtils;
|
|
2863
2909
|
exports.Lang = LangUtils;
|
|
2864
2910
|
exports.LangUtils = LangUtils;
|
|
2865
2911
|
exports.PromiseUtils = PromiseUtils;
|