@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
33 lines • 834 B
JavaScript
/**
* Check if the format of a URL is valid or not.
*
* @param url - URL to be checked.
* @returns True if the URL is valid, false otherwise.
* @throws An error if URL's constructor throws an error other than `TypeError`.
*/
export function isValidURL(url) {
try {
return Boolean(new URL(url));
}
catch (error) {
if (error instanceof TypeError)
return false;
throw error;
}
}
/**
* Safely parse a string into a URL.
*
* @param url - The string to parse into a URL.
* @returns A URL object if the parsing is successful, undefined otherwise.
*/
export function safeParseURL(url) {
try {
return new URL(url);
// eslint-disable-next-line no-catch-all/no-catch-all
}
catch (error) {
return undefined;
}
}
//# sourceMappingURL=url.js.map