Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda