@creejs/commons-lang 2.1.5 → 2.1.7

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.
@@ -127,6 +127,7 @@ var TypeUtils = {
127
127
  isNumber,
128
128
  isPositive,
129
129
  isNegative,
130
+ isNotNegative,
130
131
  isNil,
131
132
  isNullOrUndefined,
132
133
  isNull,
@@ -140,7 +141,19 @@ var TypeUtils = {
140
141
  isStream,
141
142
  isString,
142
143
  isSymbol,
143
- 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
144
157
  };
145
158
  /**
146
159
  * Checks if the given value is an array.
@@ -265,6 +278,18 @@ function isPositive (value) {
265
278
  return value > 0
266
279
  }
267
280
 
281
+ /**
282
+ * Checks if value is a number, and >=0
283
+ * @param {*} value - The value to check.
284
+ * @returns {boolean}
285
+ */
286
+ function isNotNegative (value) {
287
+ if (!isNumber(value)) {
288
+ return false
289
+ }
290
+ return value >= 0
291
+ }
292
+
268
293
  /**
269
294
  * check that a value is a Negative number.
270
295
  * @param {number} value - The value to check.
@@ -394,6 +419,106 @@ function isSymbol (value) {
394
419
  return value != null && typeof value === 'symbol'
395
420
  }
396
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
+
397
522
  // 3rd
398
523
  // internal
399
524
  // owned
@@ -405,6 +530,7 @@ var TypeAssert = {
405
530
  assertNumber,
406
531
  assertPositive,
407
532
  assertNegative,
533
+ assertNotNegative,
408
534
  assertBoolean,
409
535
  assertObject,
410
536
  assertPlainObject,
@@ -419,7 +545,19 @@ var TypeAssert = {
419
545
  assertUndefined,
420
546
  assertString,
421
547
  assertArray,
422
- 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
423
561
  };
424
562
  /**
425
563
  * if value is not Array, throw error
@@ -482,6 +620,18 @@ function assertNegative (value, paramName) {
482
620
  }
483
621
  }
484
622
 
623
+ /**
624
+ * Asserts that a value is 0 or Positive
625
+ * @param {number} value - The value to check.
626
+ * @param {string} [paramName] - Optional name of the parameter for error message.
627
+ * @throws {Error} If the value is not a number or is less than zero.
628
+ */
629
+ function assertNotNegative (value, paramName) {
630
+ if (!isNotNegative(value)) {
631
+ throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not "0 or Positive": ${value}`)
632
+ }
633
+ }
634
+
485
635
  /**
486
636
  * if value is not a string, throw error
487
637
  * @param {*} value
@@ -640,6 +790,127 @@ function assertStringOrSymbol (value, paramName) {
640
790
  }
641
791
  }
642
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
+
643
914
  // 3rd
644
915
  // internal
645
916
  // owned