Vizzuality/landgriffon

View on GitHub
client/src/utils/user-full-name.ts

Summary

Maintainability
A
35 mins
Test Coverage
import type { User } from 'types';

const getUserFullName = (user: User, options?: { replaceByEmail?: boolean }) => {
  if (!user) return '';
  const { fname, lname, email } = user;
  let name = '';
  if (fname) {
    name = fname;
  }
  if (lname) {
    name = name ? `${name} ${lname}` : lname;
  }
  if (!name && options?.replaceByEmail) return email;
  return name;
};

export default getUserFullName;