@wordpress/block-library
Version:
Block library for the WordPress editor.
20 lines (19 loc) • 740 B
JavaScript
import { privateApis } from "@wordpress/block-editor";
import { isEmail, isURL, prependHTTPS } from "@wordpress/url";
import { unlock } from "../lock-unlock.mjs";
// packages/block-library/src/social-link/is-valid-link.ts
const { isURLLike } = unlock(privateApis);
/**
* Returns whether a Social Icon's link looks valid: a URL, with or without
* its protocol, or an email address for the Mail icon. It uses the same check
* as the link popover, and an empty link is valid.
*
* @param url The link.
* @return Whether the link is valid.
*/
function isValidLink(url) {
if (!url) return true;
return isEmail(url) || !!isURLLike(url) && isURL(prependHTTPS(url));
}
export { isValidLink as default };
//# sourceMappingURL=is-valid-link.mjs.map