Percent-encode a string for use in a URL, or decode one back to readable text. Two modes, because encoding a whole URL and encoding one query parameter are different jobs with different rules.
Encode or decode URL strings. Choose between component encoding (for query params) or full URI encoding (preserves path separators).
The distinction matters more than people expect. encodeURIComponent escapes the reserved characters : / ? # [ ] @ ! $ & ' ( ) * + , ; = which is exactly what you want for a query parameter value, and exactly what you do not want for a whole URL. It would destroy the scheme and path separators. encodeURI leaves those intact. Using the wrong one is behind a large share of broken redirect and callback URLs.
Reach for component mode when you are building a query string, an OAuth redirect_uri parameter, or anything nested inside another URL. Reach for full-URI mode when you have a URL containing spaces or non-ASCII characters that needs to be made transport-safe as a whole.