// packages/block-editor/src/components/link-control/is-url-like.js
import { getProtocol, isValidProtocol, isValidFragment } from "@wordpress/url";
function isURLLike(val) {
  const hasSpaces = val.includes(" ");
  if (hasSpaces) {
    return false;
  }
  const protocol = getProtocol(val);
  const protocolIsValid = isValidProtocol(protocol);
  const mayBeTLD = hasPossibleTLD(val);
  const isWWW = val?.startsWith("www.");
  const isInternal = val?.startsWith("#") && isValidFragment(val);
  return protocolIsValid || isWWW || isInternal || mayBeTLD;
}
function hasPossibleTLD(url, maxLength = 6) {
  const cleanedURL = url.split(/[?#]/)[0];
  const regex = new RegExp(
    `(?<=\\S)\\.(?:[a-zA-Z_]{2,${maxLength}})(?:\\/|$)`
  );
  return regex.test(cleanedURL);
}
export {
  isURLLike as default
};
//# sourceMappingURL=is-url-like.js.map
