@creejs/commons-lang 2.1.6 → 2.1.8
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 +338 -5
- 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 +338 -6
- 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 +338 -5
- 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/type-assert.d.ts +84 -0
- package/types/type-utils.d.ts +84 -0
- package/types/typed-array-utils.d.ts +34 -0
package/dist/esm/index-dev.js
CHANGED
|
@@ -8,7 +8,7 @@ var LangUtils = {
|
|
|
8
8
|
defaults,
|
|
9
9
|
extend,
|
|
10
10
|
extends: extend,
|
|
11
|
-
equals,
|
|
11
|
+
equals: equals$1,
|
|
12
12
|
isBrowser,
|
|
13
13
|
isNode
|
|
14
14
|
};
|
|
@@ -76,7 +76,7 @@ function extend (target, ...sources) {
|
|
|
76
76
|
* @param {*} value2 - Second value to compare
|
|
77
77
|
* @returns {boolean} True if values are equal, false otherwise
|
|
78
78
|
*/
|
|
79
|
-
function equals (value1, value2) {
|
|
79
|
+
function equals$1 (value1, value2) {
|
|
80
80
|
if (value1 === value2) {
|
|
81
81
|
return true
|
|
82
82
|
}
|
|
@@ -137,7 +137,19 @@ var TypeUtils = {
|
|
|
137
137
|
isStream,
|
|
138
138
|
isString,
|
|
139
139
|
isSymbol,
|
|
140
|
-
isPrimitive
|
|
140
|
+
isPrimitive,
|
|
141
|
+
isInt8Array,
|
|
142
|
+
isUint8Array,
|
|
143
|
+
isUint8ClampedArray,
|
|
144
|
+
isInt16Array,
|
|
145
|
+
isUint16Array,
|
|
146
|
+
isInt32Array,
|
|
147
|
+
isUint32Array,
|
|
148
|
+
isFloat32Array,
|
|
149
|
+
isFloat64Array,
|
|
150
|
+
isBigInt64Array,
|
|
151
|
+
isBigUint64Array,
|
|
152
|
+
isTypedArray
|
|
141
153
|
};
|
|
142
154
|
/**
|
|
143
155
|
* Checks if the given value is an array.
|
|
@@ -403,6 +415,106 @@ function isSymbol (value) {
|
|
|
403
415
|
return value != null && typeof value === 'symbol'
|
|
404
416
|
}
|
|
405
417
|
|
|
418
|
+
/**
|
|
419
|
+
* Checks if a value is a typed array (e.g., Int8Array, Uint32Array, etc.).
|
|
420
|
+
* @param {*} value - The value to check.
|
|
421
|
+
* @returns {boolean} True if the value is a typed array, false otherwise.
|
|
422
|
+
*/
|
|
423
|
+
function isTypedArray (value) {
|
|
424
|
+
return ArrayBuffer.isView(value) && value.constructor !== DataView
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Checks if the given value is an Int8Array.
|
|
428
|
+
* @param {*} value - The value to check.
|
|
429
|
+
* @returns {boolean} True if the value is an Int8Array, false otherwise.
|
|
430
|
+
*/
|
|
431
|
+
function isInt8Array (value) {
|
|
432
|
+
return value instanceof Int8Array
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Checks if the given value is an instance of Uint8Array.
|
|
436
|
+
* @param {*} value - The value to check.
|
|
437
|
+
* @returns {boolean} True if the value is a Uint8Array, false otherwise.
|
|
438
|
+
*/
|
|
439
|
+
function isUint8Array (value) {
|
|
440
|
+
return value instanceof Uint8Array
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Checks if the given value is a Uint8ClampedArray.
|
|
444
|
+
* @param {*} value - The value to check.
|
|
445
|
+
* @returns {boolean} True if the value is a Uint8ClampedArray, false otherwise.
|
|
446
|
+
*/
|
|
447
|
+
function isUint8ClampedArray (value) {
|
|
448
|
+
return value instanceof Uint8ClampedArray
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Checks if the given value is an Int16Array.
|
|
452
|
+
* @param {*} value - The value to check.
|
|
453
|
+
* @returns {boolean} True if the value is an Int16Array, false otherwise.
|
|
454
|
+
*/
|
|
455
|
+
function isInt16Array (value) {
|
|
456
|
+
return value instanceof Int16Array
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Checks if the given value is a Uint16Array.
|
|
460
|
+
* @param {*} value - The value to check.
|
|
461
|
+
* @returns {boolean} True if the value is a Uint16Array, false otherwise.
|
|
462
|
+
*/
|
|
463
|
+
function isUint16Array (value) {
|
|
464
|
+
return value instanceof Uint16Array
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Checks if the given value is an Int32Array.
|
|
468
|
+
* @param {*} value - The value to check.
|
|
469
|
+
* @returns {boolean} True if the value is an Int32Array, false otherwise.
|
|
470
|
+
*/
|
|
471
|
+
function isInt32Array (value) {
|
|
472
|
+
return value instanceof Int32Array
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Checks if the given value is a Uint32Array.
|
|
476
|
+
* @param {*} value - The value to check.
|
|
477
|
+
* @returns {boolean} True if the value is a Uint32Array, false otherwise.
|
|
478
|
+
*/
|
|
479
|
+
function isUint32Array (value) {
|
|
480
|
+
return value instanceof Uint32Array
|
|
481
|
+
}
|
|
482
|
+
// export function isFloat16Array (value) {
|
|
483
|
+
// return value instanceof Float16Array
|
|
484
|
+
// }
|
|
485
|
+
/**
|
|
486
|
+
* Checks if the given value is a Float32Array.
|
|
487
|
+
* @param {*} value - The value to check.
|
|
488
|
+
* @returns {boolean} True if the value is a Float32Array, false otherwise.
|
|
489
|
+
*/
|
|
490
|
+
function isFloat32Array (value) {
|
|
491
|
+
return value instanceof Float32Array
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Checks if the given value is a Float64Array.
|
|
495
|
+
* @param {*} value - The value to check.
|
|
496
|
+
* @returns {boolean} True if the value is a Float64Array, false otherwise.
|
|
497
|
+
*/
|
|
498
|
+
function isFloat64Array (value) {
|
|
499
|
+
return value instanceof Float64Array
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Checks if the given value is a BigInt64Array.
|
|
503
|
+
* @param {*} value - The value to check.
|
|
504
|
+
* @returns {boolean} True if the value is a BigInt64Array, false otherwise.
|
|
505
|
+
*/
|
|
506
|
+
function isBigInt64Array (value) {
|
|
507
|
+
return value instanceof BigInt64Array
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Checks if the given value is a BigUint64Array instance.
|
|
511
|
+
* @param {*} value - The value to check.
|
|
512
|
+
* @returns {boolean} True if the value is a BigUint64Array, false otherwise.
|
|
513
|
+
*/
|
|
514
|
+
function isBigUint64Array (value) {
|
|
515
|
+
return value instanceof BigUint64Array
|
|
516
|
+
}
|
|
517
|
+
|
|
406
518
|
// 3rd
|
|
407
519
|
// internal
|
|
408
520
|
// owned
|
|
@@ -429,7 +541,19 @@ var TypeAssert = {
|
|
|
429
541
|
assertUndefined,
|
|
430
542
|
assertString,
|
|
431
543
|
assertArray,
|
|
432
|
-
assertStringOrSymbol
|
|
544
|
+
assertStringOrSymbol,
|
|
545
|
+
assertInt8Array,
|
|
546
|
+
assertUint8Array,
|
|
547
|
+
assertUint8ClampedArray,
|
|
548
|
+
assertInt16Array,
|
|
549
|
+
assertUint16Array,
|
|
550
|
+
assertInt32Array,
|
|
551
|
+
assertUint32Array,
|
|
552
|
+
assertFloat32Array,
|
|
553
|
+
assertFloat64Array,
|
|
554
|
+
assertBigInt64Array,
|
|
555
|
+
assertBigUint64Array,
|
|
556
|
+
assertTypedArray
|
|
433
557
|
};
|
|
434
558
|
/**
|
|
435
559
|
* if value is not Array, throw error
|
|
@@ -662,6 +786,127 @@ function assertStringOrSymbol (value, paramName) {
|
|
|
662
786
|
}
|
|
663
787
|
}
|
|
664
788
|
|
|
789
|
+
/**
|
|
790
|
+
* assert if a value is a typed array (e.g., Int8Array, Uint32Array, etc.).
|
|
791
|
+
* @param {*} value - The value to check.
|
|
792
|
+
* @param {string} paramName
|
|
793
|
+
*/
|
|
794
|
+
function assertTypedArray (value, paramName) {
|
|
795
|
+
if (isTypedArray(value)) {
|
|
796
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not TypedArray`)
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* assert if the given value is an Int8Array.
|
|
801
|
+
* @param {*} value - The value to check.
|
|
802
|
+
* @param {string} paramName
|
|
803
|
+
*/
|
|
804
|
+
function assertInt8Array (value, paramName) {
|
|
805
|
+
if (isInt8Array(value)) {
|
|
806
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Int8Array`)
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* assert if the given value is an instance of Uint8Array.
|
|
811
|
+
* @param {*} value - The value to check.
|
|
812
|
+
* @param {string} paramName
|
|
813
|
+
*/
|
|
814
|
+
function assertUint8Array (value, paramName) {
|
|
815
|
+
if (isUint8Array(value)) {
|
|
816
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Uint8Array`)
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* assert if the given value is a Uint8ClampedArray.
|
|
821
|
+
* @param {*} value - The value to check.
|
|
822
|
+
* @param {string} paramName
|
|
823
|
+
*/
|
|
824
|
+
function assertUint8ClampedArray (value, paramName) {
|
|
825
|
+
if (isUint8ClampedArray(value)) {
|
|
826
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Uint8ClampedArray`)
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* assert if the given value is an Int16Array.
|
|
831
|
+
* @param {*} value - The value to check.
|
|
832
|
+
* @param {string} paramName
|
|
833
|
+
*/
|
|
834
|
+
function assertInt16Array (value, paramName) {
|
|
835
|
+
if (isInt16Array(value)) {
|
|
836
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Int16Array`)
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* assert if the given value is a Uint16Array.
|
|
841
|
+
* @param {*} value - The value to check.
|
|
842
|
+
* @param {string} paramName
|
|
843
|
+
*/
|
|
844
|
+
function assertUint16Array (value, paramName) {
|
|
845
|
+
if (isUint16Array(value)) {
|
|
846
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Uint16Array`)
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* assert if the given value is an Int32Array.
|
|
851
|
+
* @param {*} value - The value to check.
|
|
852
|
+
* @param {string} paramName
|
|
853
|
+
*/
|
|
854
|
+
function assertInt32Array (value, paramName) {
|
|
855
|
+
if (isInt32Array(value)) {
|
|
856
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Int32Array`)
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* assert if the given value is a Uint32Array.
|
|
861
|
+
* @param {*} value - The value to check.
|
|
862
|
+
* @param {string} paramName
|
|
863
|
+
*/
|
|
864
|
+
function assertUint32Array (value, paramName) {
|
|
865
|
+
if (isUint32Array(value)) {
|
|
866
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Uint32Array`)
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* assert if the given value is a Float32Array.
|
|
871
|
+
* @param {*} value - The value to check.
|
|
872
|
+
* @param {string} paramName
|
|
873
|
+
*/
|
|
874
|
+
function assertFloat32Array (value, paramName) {
|
|
875
|
+
if (isFloat32Array(value)) {
|
|
876
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Float32Array`)
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* assert if the given value is a Float64Array.
|
|
881
|
+
* @param {*} value - The value to check.
|
|
882
|
+
* @param {string} paramName
|
|
883
|
+
*/
|
|
884
|
+
function assertFloat64Array (value, paramName) {
|
|
885
|
+
if (isFloat64Array(value)) {
|
|
886
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not Float64Array`)
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* assert if the given value is a BigInt64Array.
|
|
891
|
+
* @param {*} value - The value to check.
|
|
892
|
+
* @param {string} paramName
|
|
893
|
+
*/
|
|
894
|
+
function assertBigInt64Array (value, paramName) {
|
|
895
|
+
if (isBigInt64Array(value)) {
|
|
896
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not BigInt64Array`)
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* assert if the given value is a BigUint64Array instance.
|
|
901
|
+
* @param {*} value - The value to check.
|
|
902
|
+
* @param {string} paramName
|
|
903
|
+
*/
|
|
904
|
+
function assertBigUint64Array (value, paramName) {
|
|
905
|
+
if (isBigUint64Array(value)) {
|
|
906
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not BigUint64Array`)
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
665
910
|
// 3rd
|
|
666
911
|
// internal
|
|
667
912
|
// owned
|
|
@@ -1612,6 +1857,92 @@ var ReflectUtils = {
|
|
|
1612
1857
|
getMethodsOfObject: getMethods
|
|
1613
1858
|
};
|
|
1614
1859
|
|
|
1860
|
+
// internal
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
// owned
|
|
1864
|
+
|
|
1865
|
+
/**
|
|
1866
|
+
* @typedef {
|
|
1867
|
+
Int8Array|
|
|
1868
|
+
Uint8Array|
|
|
1869
|
+
Uint8ClampedArray|
|
|
1870
|
+
Int16Array|
|
|
1871
|
+
Uint16Array|
|
|
1872
|
+
Int32Array|
|
|
1873
|
+
Uint32Array|
|
|
1874
|
+
Float32Array|
|
|
1875
|
+
Float64Array|
|
|
1876
|
+
BigInt64Array|
|
|
1877
|
+
BigUint64Array
|
|
1878
|
+
} TypedArray
|
|
1879
|
+
*/
|
|
1880
|
+
|
|
1881
|
+
var TypedArrayUtils = {
|
|
1882
|
+
startsWith,
|
|
1883
|
+
isSameType,
|
|
1884
|
+
equals
|
|
1885
|
+
};
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* Checks if a string starts with the specified substring.
|
|
1889
|
+
* @param {TypedArray} src - The source string to check.
|
|
1890
|
+
* @param {TypedArray} searching - The substring to search for at the start of `src`.
|
|
1891
|
+
* @returns {boolean} True if `src` starts with `searching`, false otherwise.
|
|
1892
|
+
* @throws {Error} If either `src` or `searching` is null or undefined.
|
|
1893
|
+
*/
|
|
1894
|
+
function startsWith (src, searching) {
|
|
1895
|
+
assertNotNil(src, 'src');
|
|
1896
|
+
assertNotNil(searching, 'searching');
|
|
1897
|
+
|
|
1898
|
+
const header = src.subarray(0, searching.length);
|
|
1899
|
+
return equals(header, searching)
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
/**
|
|
1903
|
+
* Checks if two values have the same constructor type.
|
|
1904
|
+
* @param {*} src - The source value to compare.
|
|
1905
|
+
* @param {*} target - The target value to compare against.
|
|
1906
|
+
* @returns {boolean} True if both values have the same constructor type, false otherwise.
|
|
1907
|
+
* @throws Will throw if either src or target is null/undefined.
|
|
1908
|
+
*/
|
|
1909
|
+
function isSameType (src, target) {
|
|
1910
|
+
assertNotNil(src, 'src');
|
|
1911
|
+
assertNotNil(target, 'target');
|
|
1912
|
+
return constructorName(src) === constructorName(target)
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* Checks if two typed arrays are equal by comparing their contents.
|
|
1917
|
+
* 1. Must be Same Type
|
|
1918
|
+
* 2. Must have Same Length
|
|
1919
|
+
* 3. Must have same contents
|
|
1920
|
+
* @param {TypedArray} src - The source typed array to compare.
|
|
1921
|
+
* @param {TypedArray} target - The target typed array to compare against.
|
|
1922
|
+
* @returns {boolean} True if the typed arrays are equal, false otherwise.
|
|
1923
|
+
* @throws {Error} If either `src` or `target` is null or undefined.
|
|
1924
|
+
*/
|
|
1925
|
+
function equals (src, target) {
|
|
1926
|
+
assertNotNil(src, 'src');
|
|
1927
|
+
assertNotNil(target, 'target');
|
|
1928
|
+
if (!isSameType(src, target)) {
|
|
1929
|
+
return false
|
|
1930
|
+
}
|
|
1931
|
+
if (src.byteLength !== target.byteLength) {
|
|
1932
|
+
return false
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
const view1 = new DataView(src.buffer, src.byteOffset, src.byteLength);
|
|
1936
|
+
const view2 = new DataView(target.buffer, target.byteOffset, target.byteLength);
|
|
1937
|
+
|
|
1938
|
+
for (let i = 0; i < src.byteLength; i++) {
|
|
1939
|
+
if (view1.getUint8(i) !== view2.getUint8(i)) {
|
|
1940
|
+
return false
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return true
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1615
1946
|
/**
|
|
1616
1947
|
* @module Lang
|
|
1617
1948
|
* @description Core language utilities for type checking, string manipulation, and common operations.
|
|
@@ -1630,8 +1961,9 @@ var index = {
|
|
|
1630
1961
|
Exec: ExecUtils,
|
|
1631
1962
|
ClassProxyUtils,
|
|
1632
1963
|
InstanceProxyUtils,
|
|
1633
|
-
ReflectUtils
|
|
1964
|
+
ReflectUtils,
|
|
1965
|
+
TypedArrayUtils
|
|
1634
1966
|
};
|
|
1635
1967
|
|
|
1636
|
-
export { ClassProxyUtils, ExecUtils as Exec, ExecUtils, InstanceProxyUtils, LangUtils as Lang, LangUtils, PromiseUtils, ReflectUtils, StringUtils, TypeUtils as Type, TypeAssert, TypeUtils, index as default };
|
|
1968
|
+
export { ClassProxyUtils, ExecUtils as Exec, ExecUtils, InstanceProxyUtils, LangUtils as Lang, LangUtils, PromiseUtils, ReflectUtils, StringUtils, TypeUtils as Type, TypeAssert, TypeUtils, TypedArrayUtils, index as default };
|
|
1637
1969
|
//# sourceMappingURL=index-dev.js.map
|