const formatName = (author) => {
  if (!author || typeof author.name !== 'string') {
    return '';
  }

  const authorName = author.name.trim().split(' ');
  if (authorName.length < 2) {
    return authorName.join(' ');
  }

  const firstName = authorName[0];
  const lastName = authorName[authorName.length - 1];
  const updatedAuthorName = `${firstName} ${lastName.charAt(0)}.`;

  return updatedAuthorName;
};

export default formatName;
