When to use it
Putting Unicode, spaces, or symbols into a URL safely. Or doing the
reverse: turning a %E3%81%82%E3%81%84 log line back into something a
human can read.
componentURI vs uri
Two encoding scopes:
- componentURI — same as
encodeURIComponent. Escapes reserved characters too (: / ? # & =). Use it for query values, path segments, and POST bodies. - uri — same as
encodeURI. Leaves reserved characters intact and only escapes spaces and non-ASCII. Use it when you have a full URL string and don't want its structure rearranged.
When in doubt pick componentURI. Reach for uri only when you're
making a complete URL safe in one shot.
Decoding
If the input isn't valid percent-encoded text, decoding fails. The tool surfaces an error so you can see where the problem is, instead of silently chewing on bad bytes.
Tokens / keys inside query strings safe
encodeURIComponent · encodeURI both call stdlib directly. URLs containing Hangul, emoji, or auth tokens all process inside the page.