🔗 URL Encode/Decode
The end of garbled parameters. Use encodeURIComponent for parameter values and encodeURI for a whole URL.
FAQ
What's the difference between encodeURI and encodeURIComponent?
encodeURI does not encode ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #, making it suitable for encoding a whole URL; encodeURIComponent encodes more characters (including /?&=), making it suitable for encoding a single parameter value, so an & inside the value isn't mistaken for a separator.
What if decoding fails?
It's usually because the string contains a lone % (not in %XX form). Check your input, or encode it first and then decode it to verify.