Percent-encode a full URL (`encodeURI`) or a single component (`encodeURIComponent`), and decode. Using the wrong one is how `?q=a+b` turns into a 400. This is not HTML entity encoding.
A query value has spaces and ampersands. That is this page: encodeURI vs encodeURIComponent, plus decode.
HTML entity encoder is &. Slugify is a permalink.
Which function
- encodeURI — you already have a full URL and need non-ASCII / spaces fixed without breaking
?and&. - encodeURIComponent — one parameter value.
encodeURIComponent("a&b=c") // a%26b%3Dc
encodeURI("https://ex.test/?q=a b") // encodes the space, keeps ? and =
Honest limits
- Not a URL parser/builder with punycode UI.
- Not Base64.
- Wrong decode of form
+is on you.
This is a local encoder, not a crawler.