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

180
Views
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 answers
Answer question

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 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!