📜  Node.js util.types.isUint8ClampedArray() 方法

📅  最后修改于: 2022-05-13 01:56:31.058000             🧑  作者: Mango

Node.js util.types.isUint8ClampedArray() 方法

util.types.isUint8ClampedArray() 方法是 util 模块的内置应用程序编程接口,主要用于支持 Node.js 自身内部 API 的需求。

util.types.isUint8ClampedArray() 方法用于检查给定值是否为无符号 8 位钳位整数数组。

句法:

util.types.isUint8ClampedArray( value )

参数:此函数接受如上所述和如下所述的单个参数:

  • value:检查无符号 8 位钳位整数数组的值。

返回值:它返回一个布尔值,即如果传递的值是一个无符号的 8 位钳位整数数组,则返回 true,否则返回false

下面的示例说明了 Node.js 中的util.types.isUint8ClampedArray() 方法

示例 1:

// Node.js program to demonstrate the
// util.types.isUint8ClampedArray() method
   
// Import the util module
const util = require('util');
   
// Checking for a unsigned 8-bit
// clamped integer array
isUint8ClampedArr = util.types.isUint8ClampedArray(
                    new Uint8ClampedArray());
  
console.log("Object is Unsigned 8-bit clamped array"
                  + " object:", isUint8ClampedArr);
   
// Checking for a unsigned 8-bit
// unclamped integer array
isUint8ClampedArr = util.types.isUint8ClampedArray(
                    new Uint8Array());
  
console.log("Object is Unsigned 8-bit clamped"
                  + " array object:", isUint8ClampedArr);
   
// Checking for a integer array
isUint8ClampedArr = util.types.isUint8ClampedArray(
                  new Int8Array());
  
console.log("Object is Unsigned 8-bit clamped "
                  + "array object:", isUint8ClampedArr);

输出:

Object is Unsigned 8-bit clamped array object: true
Object is Unsigned 8-bit clamped array object: false
Object is Unsigned 8-bit clamped array object: false

示例 2:

// Node.js program to demonstrate the
// util.types.isUint8ClampedArray() method
   
// Import the util module
const util = require('util');
   
// Checking a big unsigned 64-bit
// integer array
let UintClampedArr = 
    new Uint8ClampedArray([0, 128, 1024, 2054]);
  
console.log(UintClampedArr);
   
isUint8ClampedArr = 
    util.types.isUint8ClampedArray(UintClampedArr);
  
console.log("Object is Unsigned 8-bit clamped"
            + " array object:", isUint8ClampedArr);
   
// Checking a unsigned 32-bit integer array
let unsigned32Arr = new Uint32Array([4, 25, 128]);
console.log(unsigned32Arr);
   
isUint8ClampedArr = 
    util.types.isUint8ClampedArray(unsigned32Arr);
console.log("Object is Unsigned 8-bit clamped"
            + " array object:", isUint8ClampedArr);
   
// Checking a big signed 64-bit integer array
let bigSigned64Arr = new BigInt64Array([16n, 25n, 128n]);
console.log(bigSigned64Arr);
   
isUint8ClampedArr = 
    util.types.isUint8ClampedArray(bigSigned64Arr);
console.log("Object is Unsigned 8-bit clamped"
            + " array object:", isUint8ClampedArr);

输出:

Uint8ClampedArray [ 0, 128, 255, 255 ]
Object is Unsigned 8-bit clamped array object: true
Uint32Array [ 4, 25, 128 ]
Object is Unsigned 8-bit clamped array object: false
BigInt64Array [ 16n, 25n, 128n ]
Object is Unsigned 8-bit clamped array object: false

参考: https://nodejs.org/api/util.html#util_util_types_isuint8clampedarray_value