Created
December 13, 2020 11:33
-
-
Save erikvullings/c3d29688c2439654f54dda9ae8434f56 to your computer and use it in GitHub Desktop.
Capitalize first names derived from an email address (Dutch)
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
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); | |
/** Capitalize first names that are derived from an email, like anne_merel or jan_willem. */ | |
export const capitalizeName = (s: string) => | |
/^ij/i.test(s) // names like IJsbrand | |
? s.replace(/^ij/i, 'IJ') | |
: /_/.test(s) // names like jan_willem | |
? s.split('_').map(capitalize).join('-') | |
: capitalize(s); // other names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment