12 lines
384 B
TypeScript
12 lines
384 B
TypeScript
function getInitialsUtils(name) {
|
|
if (!name || typeof name !== 'string') return '';
|
|
|
|
return name
|
|
.trim()
|
|
.split(/\s+/) // split by spaces (handles multiple spaces)
|
|
.filter(word => word.length) // remove empty strings
|
|
.map(word => word[0]) // take first letter of each word
|
|
.join('');
|
|
}
|
|
|
|
export default getInitialsUtils; |