URL encode / decode
Clearly separates encodeURI (preserves URL structure) from encodeURIComponent (escapes structural characters), plus application/x-www-form-urlencoded form encoding. Only form decoding treats + as a space; %2B always remains a literal plus.
Inputs and parameters
input— Input text or encoded stringmode— Mode
Real example
input=https://ex.test/a b?x=1&y=2
→ encodeURI → https://ex.test/a%20b?x=1&y=2; encodeURIComponent → https%3A%2F%2Fex.test%2Fa%20b%3Fx%3D1%26y%3D2. form encode "a b+c" → a+b%2Bc; decodeURI("a+b%20c") → a+b c (+ stays a plus), decode-form("a+b%2Bc") → a b+c.
Limits and failure handling
String transforms only: no URL parsing/assembly, no query key/value parsing, no double decoding. Invalid %XX or incomplete UTF-8 raises INVALID_PERCENT_ENCODING. Form mode percent-encodes UTF-8 bytes with uppercase hex. Input cap 1 MiB; the URL is never opened or fetched.
FAQ
When is + a space?
Only in decode-form (application/x-www-form-urlencoded). In decodeURI / decodeURIComponent, + is a literal character; %2B is a real plus and is never treated as a space in every context.
Which encoder should I use?
Use encodeURI for a whole URL whose structure must survive; use encodeURIComponent for a single value placed inside a query parameter.