Frontend first draft
This commit is contained in:
17
frontend/pshared/lib/utils/name_initials.dart
Normal file
17
frontend/pshared/lib/utils/name_initials.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
class NameInitials {
|
||||
|
||||
static const unknown = '?';
|
||||
|
||||
}
|
||||
|
||||
|
||||
String getNameInitials(String name) {
|
||||
if (name.isEmpty) return NameInitials.unknown;
|
||||
// Split the name by whitespace.
|
||||
final words = name.trim().split(RegExp(r'\s+'));
|
||||
if (words.isEmpty) return NameInitials.unknown;
|
||||
// If there's only one word, return its first letter.
|
||||
if (words.length == 1) return words.first[0].toUpperCase();
|
||||
// Otherwise, use the first letter of the first and last words.
|
||||
return (words.first[0] + words.last[0]).toUpperCase();
|
||||
}
|
||||
Reference in New Issue
Block a user