fullName method

String fullName([
  1. NameOrder? orderedBy
])

Gets the full name ordered as configured.

The name order orderedBy forces to order by first or last name by overriding the preset configuration.

Namefully.format may also be used to alter manually the order of appearance of full name.

For example:

var name = Namefully('Jon Stark Snow');
print(name.fullName(NameOrder.lastName)); // "Snow Jon Stark"
print(name.format('l f m')); // "Snow Jon Stark"

Implementation

String fullName([NameOrder? orderedBy]) {
  var sep = _config.ending ? ',' : '';
  orderedBy ??= _config.orderedBy;

  return <String>[
    if (prefix != null) prefix!,
    if (orderedBy == NameOrder.firstName) ...[
      first,
      ...middleName(),
      last + sep,
    ] else ...[
      last,
      first,
      middleName().join(' ') + sep
    ],
    if (suffix != null) suffix!,
  ].join(' ').trim();
}