"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.resolveInnerUrl = void 0;
const URL_REGEX = /https?:\/\/[^\s]+/i;
const TRAILING_PUNCTUATION_REGEX = /[.,!?;:]$/;
const resolveInnerUrl = (text, url) => {
  if (url) return {
    innerUrl: url,
    text
  };
  if (!text) return {
    innerUrl: undefined,
    text
  };
  const [matchedUrl] = text.match(URL_REGEX) || [];
  if (!matchedUrl) return {
    innerUrl: undefined,
    text
  };
  const cleanUrl = matchedUrl.replace(TRAILING_PUNCTUATION_REGEX, '');
  const textWithoutUrl = text.replace(matchedUrl, '').replace(/\s{2,}/g, ' ').trim();
  return {
    innerUrl: cleanUrl,
    text: textWithoutUrl
  };
};
exports.resolveInnerUrl = resolveInnerUrl;
//# sourceMappingURL=resolveInnerUrl.js.map