Open In App

Node.js util.types.isUint8ClampedArray() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The util.types.isUint8ClampedArray() method is an inbuilt application programming interface of util module which is primarily designed to support the needs of Node.js own internal APIs.

The util.types.isUint8ClampedArray() method is used to check if the given value is an unsigned 8-bit clamped integer array or not.

Syntax:

util.types.isUint8ClampedArray( value )

Parameters: This function accepts single parameter as mentioned above and described below:

  • value: It is the value that would be checked for an unsigned 8-bit clamped integer array.

Return Value: It returns a boolean value i.e. true if the passed value is an unsigned 8-bit clamped integer array otherwise returns false.

Below examples illustrate the util.types.isUint8ClampedArray() method in Node.js:

Example 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);


Output:

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

Example 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);


Output:

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

Reference: https://nodejs.org/api/util.html#util_util_types_isuint8clampedarray_value



Last Updated : 12 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads