Skip to content

Instantly share code, notes, and snippets.

@vicainelli
Created May 20, 2021 10:12
Show Gist options
  • Save vicainelli/dd2744f554fdd14b71a2f7214b9478e0 to your computer and use it in GitHub Desktop.
Save vicainelli/dd2744f554fdd14b71a2f7214b9478e0 to your computer and use it in GitHub Desktop.
Extract two initials from name string
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