Skip to content

Commit

Permalink
feat(extension-utils): created for String
Browse files Browse the repository at this point in the history
Signed-off-by: kapdroid <kapilsharma130519@gmail.com>
  • Loading branch information
kapdroid committed Dec 19, 2024
1 parent 837183d commit 67d196d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/src/utils/extension_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//extension on String
extension StringExtension on String {
String getTwoInitials() {
final stringChars = this.split("");
final first = stringChars.firstOrNull?.toUpperCase();
if (first == null) {
return this;
}

final words = this.trim().split(" ");
final last =
(words.last.length > 1 ? words.last.substring(0, 1) : stringChars.last)
.toUpperCase();
return "$first$last";
}
}

0 comments on commit 67d196d

Please sign in to comment.