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
相关用法
注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 Node.js | util.types.isUint8ClampedArray() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。