Encode and decode URLs, query strings, and special characters. Supports both encodeURI and encodeURIComponent.
URL encoding (percent-encoding) replaces unsafe ASCII characters with a % followed by two hexadecimal digits. This is required because URLs can only contain a limited set of characters from the ASCII set. Spaces become %20, ampersands become %26, and so on.
encodeURI encodes a full URI, preserving characters like :, /, ?, #, and & that have special meaning in URLs. encodeURIComponent encodes everything except letters, digits, and - _ . ~ making it ideal for encoding individual query parameter values.
Use encodeURIComponent when encoding a single query parameter value (e.g., a search term). Use encodeURI when encoding a complete URL that should remain navigable.