Created
May 20, 2021 10:12
-
-
Save vicainelli/dd2744f554fdd14b71a2f7214b9478e0 to your computer and use it in GitHub Desktop.
Extract two initials from name string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const makeInitial = (name) => { | |
const rgx = new RegExp(/(\p{L}{1})\p{L}+/, 'gu'); | |
let initials = [...name.matchAll(rgx)] || []; | |
return ( | |
(initials.shift()?.[1] || '') + (initials.pop()?.[1] || '') | |
).toUpperCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment