"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.findLinkMark = findLinkMark;
exports.isSafeUrl = void 0;
exports.normalizeUrl = normalizeUrl;
var whitelistedURLPatterns = [/^https?:\/\//im, /^ftps?:\/\//im, /^\//im, /^mailto:/im, /^skype:/im, /^callto:/im, /^facetime:/im, /^git:/im, /^irc6?:/im, /^news:/im, /^nntp:/im, /^feed:/im, /^cvs:/im, /^svn:/im, /^mvn:/im, /^ssh:/im, /^scp:\/\//im, /^sftp:\/\//im, /^itms:/im, /^notes:/im, /^hipchat:\/\//im, /^sourcetree:/im, /^urn:/im, /^tel:/im, /^xmpp:/im, /^telnet:/im, /^vnc:/im, /^rdp:/im, /^whatsapp:/im, /^slack:/im, /^sips?:/im, /^magnet:/im];

var isSafeUrl = function isSafeUrl(url) {
  return whitelistedURLPatterns.some(function (p) {
    return p.test(url.trim()) === true;
  });
};

exports.isSafeUrl = isSafeUrl;

function normalizeUrl(url) {
  if (!url) {
    return '';
  }

  return isSafeUrl(url) ? url : 'http://' + url;
}

function findLinkMark(node) {
  var _node$marks;

  return node === null || node === void 0 ? void 0 : (_node$marks = node.marks) === null || _node$marks === void 0 ? void 0 : _node$marks.find(function (m) {
    return m.type.name == 'link';
  });
}