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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

{}
Object is a proxy instance: true
{ a: '1', b: '2' }
Object is a proxy instance: false

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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()));

chevron_right


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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.