Node.js util.types.isProxy() Method
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:
// Node.js program to demonstrate the // util.types.isProxy() method // Import the util module const util = require( 'util' ); // Creating a target const target = {}; // Checking the proxy instance let proxyObj = new Proxy(target, {}); console.log(proxyObj); isProxy = util.types.isProxy(proxyObj); console.log( "Object is a proxy instance:" , isProxy); // Checking a normal object 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:
// Node.js program to demonstrate the // util.types.isProxy() method // Import the util module const util = require( 'util' ); // Creating a target const target = {}; // Checking the proxy object console.log( "Object is a proxy instance:" ); console.log(util.types.isProxy( new Proxy(target, {}))); // Checking a normal object 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
Please Login to comment...