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