-
-
Save devbyray/5f880b0e20a36080be49487335a2cffe to your computer and use it in GitHub Desktop.
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
public formatInitials(value: string): string { | |
if (!value || value === '') { | |
return value; | |
} | |
let format = value.split('').map((val) => val.toUpperCase()); | |
let formatted = []; | |
if (value.toLowerCase().includes('th')) { | |
const regex = /(\bth\b)/gm; | |
format = value.trim().split(regex); | |
formatted = format | |
.filter((val) => /\w+/gm.test(val)) | |
.map((val) => { | |
return val.trim().split(/\W+/gm); | |
}) | |
.flat(); | |
} else { | |
formatted = format.map((val) => val.trim()); | |
} | |
const voorletters = | |
formatted | |
.filter((val) => /\w+/gm.test(val)) | |
.map((val) => val.trim().replace('.', '').replace(',', '')) | |
.map((val) => { | |
if (!val.toLowerCase().includes('th')) { | |
return val.toUpperCase(); | |
} | |
return val; | |
}) | |
.join('.') + '.'; | |
return voorletters; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment