Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
Npm module with different code with and without proxy support

How can I create a javascript library (distributed as module on npm) with different implementations depending on whether the environment it gets run in (transpiled to??) has proxy support or not?

As I understand it babel doesn't (at least easily) support transpilling proxies so this isn't easily fixable just via transpilation.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have a few options:

1: Use a Proxy polyfill

An example is this (which I think should be good enough) or this.

2: Check whether the Proxy variable exists

Unless you declared a variable named Proxy, I think this should be good enough.

console.log(typeof Proxy !== 'undefined')

This will output a Boolean value whether Proxy is available.
Example usage of the above:

if(typeof Proxy !== 'undefined') {
  // run code that uses Proxies
  console.log('I can use Proxies here!')
}
else {
  // run code that doesn't use Proxies
  console.log('Oops! I can\'t use Proxies here!')
}

NOTE: You have to use typeof to check whether the Proxy variable exists or not, as it will just return undefined instead of throwing an error.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!