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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。