More details
The encodeURIComponent() function encodes a URI by substituting each occurrence of specific characters with one, two, three, or four escape sequences, which represent the UTF-8 encoding of the character. (For characters composed of two surrogate characters, there will be four escape sequences.) Unlike encodeURI(), this function encodes a broader range of characters, encompassing those integral to the URI syntax.
/**
* ๐ช Qit.tools
* https://qit.tools
*
* Encodes a URL component by escaping characters that have special meanings in URLs.
* @param {string} input - The URL component to encode.
* @returns {string} - The encoded URL component.
*/
export function encodeURL(input: string): string {
if (typeof input !== "string") {
throw new Error("Input must be a string.");
}
try {
return encodeURIComponent(input);
} catch (error) {
throw new Error("Failed to encode the URL component.");
}
}