Enhancement: Exclusion of Prepositions and Modification of Initials
Closed this issue · 1 comments
I would like to propose an enhancement to the current functionality of the component. Currently, prepositions such as "de" or "das" in full names are included in the component's display. I suggest that these prepositions be excluded, and the preference be given to displaying the initials of the first and last names.
Current Behavior:
For example, with the name "Maria das Graças Rodrigues," the current display is "Md."
Desired Behavior:
I propose that the display exclude prepositions, resulting in "MR" for the same name. Additionally, the function should respect the desired length for the displayed initials.
Implementation Suggestion:
To implement this enhancement, I recommend updating the getInitialFromMultipleWords
function in the laravolt/avatar/src/Generator/DefaultGenerator.php
file as follows:
protected function getInitialFromMultipleWords($words, $length)
{
// Get the first letter of the first name
$firstInitial = Str::substr($words->first(), 0, 1);
// Get the first letter of the last name
$lastInitial = Str::substr($words->last(), 0, 1);
// Concatenate the initials and limit the length according to the $length variable
$result = $firstInitial . $lastInitial;
return Str::substr($result, 0, $length);
}
It's important to note that, despite the existence of the $length
parameter, the function currently returns only two initials: the first and last names. Adjustments are needed to accommodate the desired variable length for initials.
You can implement your own helper to cleansing the name