Node.js util.types.isProxy() Method
Last Updated :
11 Oct, 2021
The util.types.isProxy() 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.isProxy() method is used to check if the given value is a proxy instance or not.
Syntax:
util.types.isProxy( value )
Parameters: This function accepts single parameter as mentioned above and described below:
- value: It is the value that would be checked for a proxy instance.
Return Value: It returns a boolean value i.e. true if the passed value is a proxy otherwise returns false.
Below programs illustrate the util.types.isProxy() method:
Example 1:
const util = require( 'util' );
const target = {};
let proxyObj = new Proxy(target, {});
console.log(proxyObj);
isProxy = util.types.isProxy(proxyObj);
console.log( "Object is a proxy instance:" , isProxy);
normalObj = {a: "1" , b: "2" };
console.log(normalObj);
isProxy = util.types.isProxy(normalObj);
console.log( "Object is a proxy instance:" , isProxy);
|
Output:
{}
Object is a proxy instance: true
{ a: '1', b: '2' }
Object is a proxy instance: false
Example 2:
const util = require( 'util' );
const target = {};
console.log( "Object is a proxy instance:" );
console.log(util.types.isProxy( new Proxy(target, {})));
console.log( "Object is a proxy instance:" );
console.log(util.types.isProxy( new Object()));
|
Output:
Object is a proxy instance:
true
Object is a proxy instance:
false
Reference: https://nodejs.org/api/util.html#util_util_types_isproxy_value
Share your thoughts in the comments
Please Login to comment...