UNPKG

@lodestar/utils

Version:

Utilities required across multiple lodestar packages

28 lines 985 B
export function isValidHttpUrl(urlStr) { let url; try { url = new URL(urlStr); // `new URL` encodes the username/password with the userinfo percent-encode set. // This means the `%` character is not encoded, but others are (such as `=`). // If a username/password contain a `%`, they will not be able to be decoded. // // Make sure that we can successfully decode the username and password here. // // Unfortunately this means we don't accept every character supported by RFC-3986. decodeURIComponent(url.username); decodeURIComponent(url.password); } catch (_) { return false; } return url.protocol === "http:" || url.protocol === "https:"; } /** * Sanitize URL to prevent leaking user credentials in logs or metrics * * Note: `urlStr` must be a valid URL */ export function toPrintableUrl(urlStr) { return new URL(urlStr).origin; } //# sourceMappingURL=url.js.map