String Encoder

Utilty to URI-encode strings 3 ways.

Add the method names suggest, these are generally useful when you need to include some string in a URL. Which one is appropriate depends on the situation. Below are some examples of how we find them useful.

  • escape is the oldest method, and does the least; we have not had occasion to use it in our apps
  • encodeURI is generally adequate for strings that will be passed as the values for URL parameters
  • encodeURIComponent is most thorough encoder, but generally you only need it for strings that will be used as part of a URL domain/path, or if you need to pass a URL as a parameter (we do this frequently in passing API requests to proxies via AJAX)

String to encode:

Encode it!