export function format(first, middle, last) {
  return ((first || '') +
    (middle ? ` ${middle}` : '') +
    (last ? ` ${last}` : ''));
}
export const getInitials = ({ firstName, lastName }) => `${firstName[0]}${lastName[0]}`;
export const getFullName = ({ firstName, lastName }) => `${firstName} ${lastName}`;
const urlRegex = new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?");
export const hasLink = (inputText) => urlRegex.test(inputText);
// http://, https://, ftp://
const urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;
// www. sans http:// or https://
const pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
// Email addresses
const emailAddressPattern = /[\w.-]+@[a-zA-Z_-]+?(?:\.[a-zA-Z]{2,6})+/gim;
export const linkify = (text) => {
  if (!text) {
    return '';
  }
  if (!text.replace) {
    return text;
  }
  return text
    .replace(urlPattern, '<a href="$&">$&</a>')
    .replace(pseudoUrlPattern, '$1<a href="http://$2">$2</a>')
    .replace(emailAddressPattern, '<a href="mailto:$&">$&</a>')
    .replace(/\n/g, '<br />'); // keep new lines
};
