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

179
Visualizações
encodeURIComponent but in lowercase

I have some requirements which would be easily fulfilled by using the encodeURIComponent straight up, but life is never easy, because of the particular workings of this client's system, we need to encode things that come from a database in a url format (e.g. products/household+products/) and turn it into a storage blob which has to follow the 'encoded' format (products%2Fhousehold%2Bproducts%2F), however, it has to be lower case (%2F -> %2F).

The second however comes where the client also has regionalised pages and those have to remain uppercase (e.g. products/GB/household+products). That GB has to remain uppercase so I can't carpet bomb the whole thing with .toLowerCase()

Any thoughts?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use a regex to match the encoded "bytes" and convert them to lowercase:

function encode(text) {
    const uriEncoded = encodeURIComponent(text);
    return uriEncoded.replace(/%\w\w/g, match => match.toLowerCase());
}

Which produces:

> encode("products/GB/household+products")
'products%2fGB%2fhousehold%2bproducts'

You can see that GB is preserved while %2f and %2b are lowercase.

It is also easy to decode, use the same approach but you first have to convert to uppercase and then decode normally.

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