(name: string, maxInitials = 2)
| 48 | const space = new RegExp(/\s+/); |
| 49 | |
| 50 | export function getInitials(name: string, maxInitials = 2) { |
| 51 | // removes any character that is not a letter, number or whitespace |
| 52 | const cleanedName = name.replace(whiteSpace, ''); |
| 53 | |
| 54 | const words = cleanedName.trim().split(space).slice(0, maxInitials); |
| 55 | |
| 56 | return words |
| 57 | .map((word) => word.charAt(0)) |
| 58 | .join('') |
| 59 | .toUpperCase(); |
| 60 | } |
no test coverage detected